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! |
Nowadays, surfing the Internet with mobile termin...
01 Mini Program Breakthrough Plan Since Alipay op...
While we are still struggling to decide whether t...
5G, big data, artificial intelligence (AI), the I...
V5.NET is offering a limited promotion for the HK...
The completion of the project of "5G Message...
More and more industry cases tell us that F5G (fi...
2020 is destined to be an extraordinary year beca...
Unlike the fierce price competition in the 3G and...
Since 2019, countries have successively issued 5G...
Although 5G (fifth-generation mobile communicatio...
[51CTO.com Quick Translation] Dennis Rocks, produ...
[Original article from 51CTO.com] Traditional ent...
Who are the top players in 5G? A report from rese...
Despite turbulent times, Wi-Fi has had a stellar ...