Adding and deleting users is one of the basic tasks that every system administrator should know. In this tutorial, I am showing you two ways to add and remove users in CentOS 8 on the shell and also on the Desktop.

Prerequisites

You need to have root privileges for this tutorial to work.

By Using Graphical User Interface (GUI)

How to add a user on CentOS

Step 1. When you log in, the below-mentioned interface will appear. Click on the” Activities” present on its top left corner.

CentOS Desktop

Step 2. Click on the “Settings” icon from this window.

CentOS Settings

Step 3. Click on the search icon present on the top left corner of this interface.

Search Icon

Step 4. In the search bar, write “users”. The relevant option will appear in response to your search action. Click on that option.

Open users editor

Step 5. On the top right corner, there’s an “Unlock”. Click on that button to further proceed.

CentOS Users

Step 6. After this action, a pop-up will appear which requires authentication. Enter your password and click on “Authenticate” to continue.

Authenticate yourself as admin

Step 7. Upon successful authentication, the “Add User” button will be enabled that is present on the top right corner. Click on that button to add a new user.

Add user

Step 8. You have two options to set the account type, “Standard and Administrator”. You can select it as per your requirement.

Provide the following detail.

  • Full Name
  • Username
  • Password
  • Confirm password

Check “Set a password now” and enter your desired password.

After filling in all the required information, click on the “Add” present on the top right corner.

Details of the new CentOS user

Step 9. After clicking on the “Add”, another pop-up will appear which requires user authentication. Enter the password and click on authenticate to further proceed.

Administrator password

You can see a new “Test” user has been added.

New user has been added successfully

How to change the password of an existing user

Step 11. If you want to change the password of the user, click the user as shown in the below figure. Double click the “Password” text box. A pop up appears, check “Set a password now” and enter your new desired password. When you are done, click the “Change” button located at the top right corner.

Change password

You have successfully changed the password of the user.

How to remove a user

Step 12. To remove an existing user. Click the “Unlock” button.

A new pop up will appear, provide your password and click Authenticate.

Admin auth

Step 13. After authentication, click your desired user. Click “Remove User” located at the bottom right corner.

Select user that shall be removed

Step 14.  Click “Delete Files” to delete all the files of the user. If you want to keep files, click “Keep Files”.

Delete Files

You have successfully removed the user.

Add a user on CentOS by using the terminal

The second method involves using the terminal.

How to add a user

Step 15. When you log in, the below-mentioned interface will appear. Click the” Activities”  present on its top left corner.

Activities

 

Step 16. Click https://lh3.googleusercontent.com/-wZmKa04gcfj0Sif0M1BWmupoZU0fu6JWJi-ZI7ijDzPg8koxmv-9WLMN-whCHDSwcRYKLZTSI9HOSAKrbmI_FtnuGxeWPI34S6r1AgxtInzg36hvMiQt-fHV-4Rl3CetK5KnlKn icon.

Terminal Icon

Step 17. Log in with the root user. Enter the following command.

su -

Type root password and press “Enter” from the keyboard.

Become root user on the Terminal by using su command

 

Step 18. If you want to add a new user, the command should have the following syntax.

adduser [username]

Replace user name with the actual user name.

Suppose you want to add a new user test2, the complete command should look like the following.

adduser test2

Once you have added the user, it is time to set its password. Execute the following command on the terminal.

passwd [username]

Replace the username with the actual user name. Suppose you want to set the password of a newly added user test2. The complete command should look like the following.

passwd test2

When prompted enter your new password and type again to confirm. Press Enter from the keyboard when you are done.

User added successfully on the shell

How to change the password of an existing user

Step 19. To change the password for that user, type the following command.

passwd [username]

Replace the username with the actual user name. Suppose you want to change the password of a newly added user test2. The complete command should look like the following.

passwd test2

When prompted enter your new password and type again to confirm. Press “Enter” from the keyboard when you are done.

That’s how the password will be changed for that user.

Change password

How to remove a user

Step 20.  If you want to remove a  user, the command should have the following syntax.

userdel [username]

Replace username with the actual user name.

Suppose you want to remove user test2, the complete command should look like the following.

userdel test2

Remove user
If you want to delete the user’s home directory along with the user account, use the -r option. The command should have the following syntax.

userdel -r [username]

Suppose you want to remove the home directory of user test2, the complete command should look like the following.

userdel -r test2

remove user and delete home directory

Conclusion

You have learned how to add, delete and change the password of an existing user both by using GUI and terminal. If you have any problem, please leave your feedback in the comment section and I will look into it.

How to Add and Remove Users in CentOS 8
Avatar

Karim Buzdar

About the Author: Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. He blogs at LinuxWays.