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