How to Add and Delete Users on CentOS 8
3 min read
One of the first tasks when provisioning a new Linux server is adding and removing users. Each user can have different permission levels and specific settings for various command-line and GUI applications.
This article explains how to add and remove users on CentOS 8 systems.
To be able to create and remove users, you need to be logged in as root or user with sudo privileges.
How To Add User in CentOS 8
In CentOS, you can create a new user account using the
useradd command, followed by the username you want to create.
For example, to create a new user account named “linuxize” you would run:
sudo adduser linuxize
On success, the command doesn’t produce any output. It creates the user and the user’s home directory (
/home/linuxize) and copies 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, invoke the
passwd command followed by the username:
sudo passwd linuxize
You will be prompted to enter and confirm the password:
Changing password for user linuxize. New password: Retype new password: passwd: all authentication tokens updated successfully.
Make sure you use a strong password that contains capital and lower-case letters, numbers, and special characters.
Granting Sudo Privileges
By default on CentOS, members of the group wheel are granted with
If you want the newly created user to have administrative rights, add the user to the group:
sudo usermod -aG wheel linuxize
You can also configure the user sudo access by modifying the sudoers file.
How To Delete a User in CentOS
To delete a user account is no longer needed, invoke the
userdel command followed by the user name.
For example, to remove the user account named “linuxize” you would run:
sudo userdel linuxize
On success, the command doesn’t produce any output.
The command above will remove the user without deleting the user files. The user is also removed from any group it belonged to.
To remove a user and delete its home directory and mail spool pass the
-r option to
sudo userdel -r linuxize
We’ve shown you how to add and remove users in CentOS 8. The same commands apply for any other Linux distribution.
CentOS, as well as all other Linux distributions, is a multi-user operating system. Knowing how to add and remove users is one of the essential skills each Linux user should know.
Feel free to leave a comment if you have any questions.