How to Delete Users on CentOS 7.

How To Delete Users On CentOS 7.

In this tutorial, we will explain how to add and remove users on CentOS 7 systems.

Knowing how to add and remove users is one of the essential skills each Linux user should know.


How To Add User in CentOS

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


How To Delete a User in CentOS

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.