In an enterprise operation and maintenance environment, server user management is a basic but very important task. For example, when new employees join, we need to create accounts for them on multiple servers and assign appropriate permissions. When employees leave or their positions change, we also need to quickly disable or delete their accounts to avoid potential security risks. If we use manual methods to complete these tasks, we need to execute a series of commands on each server one by one, such as useradd, passwd, and chage, which is not only time-consuming and labor-intensive, but also prone to errors. Fortunately, Ansible provides a very convenient user module that can help us efficiently manage batch users, thereby ensuring the security and consistency of operations. The core functions of the user moduleTo learn more about the user module, we can use the ansible-doc command. Simply run the following command to view relevant information: After successfully executing the above command, the following result will be displayed: The user module provides many practical functions, including the following:
Description of common parameters:
Practical case analysisCase 1: Create development team accounts in batchesRequirement: Create accounts for 3 new developers, requiring:
Key points:
You can create users in batches by executing the following command: After successful creation, you can see the results as shown below: Case 2: Configuring Sudo Permissions for Operation and Maintenance AccountsCreate an opsadmin account and grant it password-free sudo permissions validate: 'visudo -cf %s':
After successfully executing the above command, you will see the result as shown below: Case 3: Safely delete former usersRequirement: Safely remove accounts of former employees, delete users but retain home directories. After successfully executing the following command, the defined user will be deleted, but the deleted user's home directory will be retained, as shown in the following figure: Case 4: Disable UserRequirement: Disable the charlie account but do not delete it, making sure its home directory is still retained. Successfully executing the following command will produce the following result: SummarizeAnsible's user module provides powerful automation capabilities for Linux server user management, which can greatly improve operation and maintenance efficiency and reduce human errors. This article demonstrates the following key functions through typical scenarios:
Through these cases, I believe you have mastered the basic usage of the user module and can apply it flexibly in actual work. I hope this tutorial can help you manage server users more easily and improve your operation and maintenance automation capabilities! |
On September 20, China Mobile held the 5G+ Innova...
[[354637]] This article is reprinted from the WeC...
[[427923]] This article is reprinted from the WeC...
In addition to the regular 30% off for annual pay...
[51CTO.com original article] In the golden autumn...
After more than three years of stable operation, ...
Spectrum resources are the core resources for the...
GMSA and China Telecom have released new guidelin...
Students who do front-end development know that t...
When it comes to 5G, the most classic and intuiti...
A recent analysis by Frost & Sullivan shows t...
In 2019, mobile technologies and services contrib...
Since its introduction 25 years ago, Wi-Fi has pl...
Since the promotion of 5G mobile phones and packa...