Read in 2 minutes

last updated 

How to Add and Delete Users on CentOS 7

CentOS, as well as all other Linux distributions is a multi-user operating system. Each user can have different permission level and specific settings for various command line and GUI application.

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

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

Prerequisites

You need to be logged in as root or user with sudo privileges to create and remove users.

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 copy 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.

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 the wheel group, as well as from any other groups the user was a member of.

Conclusion

In this tutorial, you learned how to add and remove users in CentOS. The same commands apply for any other Linux distribution.

Feel free to leave a comment if you have any questions.