Home // How to Add and Delete Users on CentOS/Rocky Linux

How to Add and Delete Users on CentOS/Rocky Linux

0 3 mins read
| Published on: December 14, 2022 | Last updated on: July 31, 2023

Provisioning a Linux server entails a number of steps, the first of which is managing user accounts. Different users can have access to unique settings and permissions for a wide range of command-line and graphical user interface (GUI) programs.

How to add users and delete users in CentOS 8/Rocky Linux is covered in this article.

Prerequisites

  • Root User
  • RPM based OS

How To Add Users in CentOS 8/Rocky Linux

Using the useradd command and the desired username, you can set up a new user account in CentOS.

To create a new user account with the name “pcplanet,” for instance, you would type:

sudo adduser pcplanet

When the command is executed successfully, it does not generate any results. It makes a new user and their home directory (/home/pcplanet), and it copies files from the /etc/skel directory into their new directory. The user has complete control over the files and folders contained in their home directory.

There is no need to preface your commands with sudo if you are already logged in as root.

Set a password for the new user so they can access their account. To do so, type passwd followed by the user’s password in a terminal:

sudo passwd pcplanet

Password entry and confirmation will be required.

Changing password for user pcplanet.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.

Use a lengthy password that includes both upper- and lowercase letters, numbers, and symbols.

Granting Sudo Privileges

On CentOS, the wheel group is automatically given sudo privileges.

Add the new user to the group if you want them to have admin privileges:

sudo usermod -aG wheel pcplanet

The sudoers file is also where you can set up which users have sudo privileges.

How To Delete Users in CentOS/Rocky

The userdel command, followed by the user’s name, deletes the user’s account.

To delete the pcplanet user account, for instance, you would type:

sudo userdel pcplanet

When the command is executed successfully, it does not generate any results.

When you use the command above, the user will be deleted without any of their files being destroyed. This also means that the user will no longer be a part of any groups to which it previously belonged.

Use the -r option with userdel to permanently delete a user’s home directory and mail spool.

sudo userdel -r pcplanet

Conclusion

Here, we’ve demonstrated how to add users and delete users in CentOS 8/Rocky Linux. Those instructions also work for any other flavor of Linux.

CentOS, like other Linux distributions, is designed for use by a number of different people simultaneously. One of the most fundamental abilities for any Linux user to have is the ability to add users and delete users.

If you have any questions, you can always leave a comment below.

IF YOU ARE HAVING PROBLEMS WITH THIS GUIDE, EMAIL US AT:

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

Copyright @2022-2024 All Right Reserved – PCPlanet

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. You understand and give your consent that your IP address and browser information might be processed by the security plugins installed on this site. By clicking “Accept”, you consent to the use of ALL the cookies.
.
Accept Read More

Privacy & Cookies Policy