Our Knowledge Base provides step-by-step guides, troubleshooting tips, and expert insights to help you manage VPS, dedicated servers, domains, DDoS protection, and more — all designed to make your experience with us fast, secure, and stress-free.
In this tutorial, we will explain how to add and remove users on CentOS 7 systems.
In CentOS, you can create a new user account using the useradd command-line utility.
To create a new user account named “username” you would run:
sudo adduser username
The command above displays no output. It will create the new user’s home directory (/home/username) and files from /etc/skel directory to the user’s home directory. Within the home directory, the user can write, edit, and delete files and directories.
Next, you’ll need to set a password for the new user so that the user can log in. To do so, use the passwd command:
sudo passwd username
You will be prompted to enter and confirm the password. Make sure you use a strong password.
Changing password for user username. New password: Retype new password: passwd: all authentication tokens updated successfully.
By default on CentOS, members of the group wheel are granted with sudo access.
If you want the newly created user to have administrative rights, add the user to the wheel group :
sudo usermod -aG wheel username
If you’re logged in as root, you don’t have to prepend each command with sudo.
If the user account is no longer needed, you can delete it using the deluser command-line tool.
To delete the user, without deleting the user files, run:
sudo userdel username
If you want to delete and the user’s home directory and mail spool use the -r flag:
sudo userdel -r username
On success, the userdel command doesn’t produce any output.
If the user was granted sudo privileges, it will be removed from the wheel group, as well as from any other groups the user was a member of.
In this tutorial, you learned how to add and remove users in CentOS. The same commands apply for any other Linux distribution.