Common Operations for User Management in CentOS Systems

24-01-2024 02:29:52

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.

Adding Users

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

Deleting Users

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

sudo Command

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

sudo Logs

For security reasons, CentOS records both successful and failed attempts to use sudo. The sudo logs are stored in the /var/log/secure file.