How to add and remove users on CentOS 8

Adding and removing users is one of the basic tasks that every system administrator should know. In this tutorial, I will show you two ways to add and remove users in CentOS 8 in shell as well as desktop.

Prerequisites

You must be root for this tutorial to work.

Using a graphical user interface (GUI)

How to add a user on CentOS

Step 1. When you login, the following interface will appear. Click on “Actions” in the upper left corner.

Step 2. Click the “Settings” icon in this window.

CentOS settings

Step 3. Click the search icon in the upper left corner of this interface.

Search icon

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

Open user editor

Step 5. In the upper right corner there is an “Unblock” button. Click on this button to continue.

CentOS users

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

Log in as administrator

Step 7. After successful authentication, the Add User button will be activated, which is located in the upper right corner. Click this button to add a new user.

Add user

Step 8. You have two options for setting the account type: “Standard” and “Administrator”. You can choose it according to your requirements.

Please provide the following information.

  • Full name
  • Username
  • password
  • Confirm password

Check “Set password now” and enter the desired password.

After filling in all the required information, click “Add” in the upper right corner.

Details of the new CentOS user

Step 9. After clicking on “Add”, another pop-up window will appear, requiring user authentication. Enter your password and click “Confirm” to continue.

Administrator password

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

New user added successfully

How to change the password of an existing user

Step 11. If you want to change the user’s password, click the user as shown in the figure below. Double-click the Password text box. A pop-up window will appear, check “Set password now” and enter the new desired password. When you’re done, click the “Edit” button located in the upper right corner.

Change Password

You have successfully changed the user’s password.

How to delete a user

Step 12. Delete the existing user. Click the Unblock button.

A new pop-up window will appear, enter your password and click “Authenticate”.

Admin auth

Step 13. After authentication, click the desired user. Click “Remove User” in the lower right corner.

Select the user you want to delete

Step 14. Click “Delete Files” to delete all user files. If you want to save the files, click “Save Files”.

Delete files

You have successfully deleted the user.

Add user to CentOS using terminal

The second way involves using a terminal.

How to add a user

Step 15. When you login, the interface shown below will appear. Click Actions in the upper left corner.

Events

Step 16. Click https://lh3.googleusercontent.com/-wZmKa04gcfj0Sif0M1BWmupoZU0fu6JWJi-ZI7ijDzPg8koxmv-9WLMN-whCHDSwcRYKLZTSI9HOSAKrbmI_FtnuQlFnGrxMegtR icon.

Terminal icon

Step 17. Log in as root. Enter the following command.

su -

Enter the root password and press “Enter” on your keyboard.

Become root user in Terminal with su command

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

adduser [username]

Replace username with your actual username.

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

adduser test2

After you’ve added a user, it’s time to set up a password. Run the following command on the terminal.

passwd [username]

Replace username with your actual username. Let’s say you want to set a password for the newly added user test2. The complete command should look like this.

passwd test2

If prompted, enter a new password and enter it again to confirm. When finished, press Enter on your keyboard.

User added to shell successfully

How to change the password of an existing user

Step 19. To change the password for this user, enter the following command.

passwd [username]

Replace username with your actual username. Let’s say you want to change the password of the newly added user test2. The complete command should look like this.

passwd test2

If prompted, enter a new password and enter it again to confirm. When done, press “Enter” on your keyboard.

This will change the password for this user.

Change Password

How to delete a user

Step 20. If you want to delete a user, the command must have the following syntax.

userdel [username]

Replace username with your actual username.

Suppose you want to delete user test2, the complete command should look like this.

userdel test2

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

userdel -r [username]

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

userdel -r test2

remove user and remove home directory

Conclusion

You have learned how to add, remove, and change the password of an existing user using both the GUI and the terminal. If you have any problems, please leave your feedback in the comments section and I will study it.

How to add and remove users on CentOS 8

Sidebar