One of your most common activities on a Linux server is to add or remove users. Today we present the tutorial add and delete users on CentOS 8. In this article, you will learn how to create user accounts, assign sudo privileges, and delete users on a CentOS 8 server.
We consider that you are logged into a CentOS 8 server with a non-root sudo-enabled user, but you can drop the sudo portion of all the following commands if you are logged in as root instead. Because they would work either way.
Tutorial add and delete users on CentOS 8
Add the new user by typing:
sudo adduser noodi
To give your user a password to let them log in, use the below command.
sudo passwd noodi
Now the new user is set up and ready to use, also you may be asked to type in the password twice to confirm it.
Suggested to read:
Granting Sudo Privileges to a User
In case you want to give the ability to execute commands with root (administrative) privileges to your user, you will need to give them access to sudo. To add your user to the wheel group, use the following command.
sudo usermod -aG wheel noodi
Then you will be asked to enter the password of your user account. After the correct password is submitted, the command you entered will be executed with root privileges.
Managing Users with Sudo Privileges
Although you can use the group to add and remove users with usermod, the command may not show which users are members of a group. when you need to see which users are part of the wheel group, you can use the lid command. And with the -g flag, you can reverse it and show which users belong in a group:
sudo lid -g wheel Output
To verify that the previous commands were successful and the user has the privileges that they need, the output would show you the usernames and UIDs that are associated with the group.
Delete all the user accounts that you have not used for a long time. To do this without deleting any of their files, use the below command.
sudo userdel noodi
But if you want to delete the user’s home directory along with their account, add the
-r flag to userdel:
sudo userdel -r noodi
Using the above commands, the user will be removed from any groups that they were added to. Including the wheel group while it is applicable. If you want to add another user with the same name, also add them to the wheel group again to gain sudo access.
in Conclusion, now you know, how to add and remove users from your CentOS 8 server. Try to separate users and give them only the access that is needed for them to do their job to face effective user management.
Dear user, we wish this tutorial add and delete users on CentOS 8would be helpful for you, to ask any question or review the conversation of our users about this article, please visit Ask page. Also to improve your knowledge, there are so many useful tutorials ready for Eldernode training.
In case you are interested in related articles: