User management in systems presents several challenges, such as regular maintenance, security risks, and a lack of documentation. This guide details the common operations for user management in CentOS systems, intended as a reference for system administrators of CentOS cloud servers.
To add a user in the CentOS system, the adduser command is used. For example, the command to add a user named 'test' is as follows.
adduser test
To change the password of the newly added user, use the passwd command. If the password is not changed, the new user will not have a password.
passwd test
When a user's access to the system is no longer needed, it is important to delete the user promptly. For example, the command to delete a user named 'test' is as follows.
userdel test
Adding the -r option to the userdel command will also delete the user's home directory, such as /home/test. Before using this option, ensure that you have backed up the user's home directory.
userdel -r test
The sudo command is used when a non-root user needs to execute commands as the root user. For instance, if a file /etc/test.txt can only be accessed by the root user, and other users cannot open this file, the following command can be used to open it.
sudo vi /etc/test.txt
Another more direct method is to switch from a non-root user to the root user. If the root user's password is unknown, it can be changed before switching. The commands to change the root user's password and switch to the root user are as follows.
sudo passwd root
su
If a user does not have permission to execute sudo, they can be added to the wheel group to gain such permission. For example, the command to add the user 'test' to the wheel group is as follows.
gpasswd -a test wheel
For security reasons, CentOS records both successful and failed attempts to use sudo. The sudo logs are stored in the /var/log/secure file.
23-02-2024 02:02:07
22-02-2024 03:19:32
22-02-2024 03:16:03
22-02-2024 03:14:03
22-02-2024 03:11:58