In this tutorial, we will learn how to Add and Delete Users on CentOS 8.
Adding and deleting is one of the basic tasks while learning about the Linux Operating System. Each user has different permission to access the files and run the commands.
Prerequisites
- Linux Operating System (CentOS 8, Ubuntu 20.04)
- Access of the Root User or User with sudo privileges.
How To Add User
You can create the user with the useradd
command followed by the desired username which you want to create.
In the below example, we will create a new user named as linuxpanda
.
sudo adduser linuxpanda
On successful execution, the command will not show any output. useradd
the command creates the user and Directory of the user /home/linuxpanda
. The User can edit, create, modify and delete the files and directories.
Now you have to set the password for the newly created user. To set the password enter the following command passwd
followed by the username.
sudo passwd linuxpanda
You will be prompted to enter and confirm the password:
Changing password for user linupanda. New password: Retype new password: passwd: all authentication tokens updated successfully.
Always use a strong password. The password must be a combination of alphabets, numbers, special characters. You can use Random Password Generator to generate a strong password.
Granting Sudo Privileges
In CentOS 8, All the members of the wheel group have sudo access.
If you want to grant the sudo privileges to the newly created user just simply add the new user to the wheel group.
sudo usermod -aG wheel linuxpanda
We can also grant the sudo privileges by editing or modifying the sudoers file.
How To Delete a User in CentOS
If any User is no longer needed, delete the User use userdel
command followed by the username.
For example, In the below command we will delete the User named as linuxpanda
:
sudo userdel linuxpanda
On successful execution, the command will not show any output. It will remove the user without removing the user’s directory.
To remove the User with the User’s directory fuse the userdel
command with -r
attribute.
sudo userdel -r linuxpanda
Conclusion
Through this tutorial, you can easily create and delete the User in CentOS 8. You can also use these commands to create and delete the user in any other Linux distribution.
If you guys have any queries related to this Add and Delete Users on CentOS 8 tutorial, let me know in the comments.
Leave a Reply