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! |
[51CTO.com original article] Recently, Huawei'...
If 5GToC helped operators achieve a return to bas...
[[413152]] Commercial building renovation Commerc...
Translator | Li Rui Review | Chonglou 51CTO Reade...
Private 5G is the next evolution of networks for ...
On June 2, it was reported that the technical sta...
Enterprises are constantly seeking to grow and tr...
Michael Porter, a famous American strategic exper...
Earlier this month, I shared the promotional VPS/...
[[388835]] The COVID-19 pandemic has driven deman...
As enterprises gradually establish their own digi...
1. Overview At present, video classification algo...
We often hear network operators and equipment ven...
[[340662]] This article is reprinted from the WeC...
5G is closely tied to edge computing. With a whol...