When configuring a new Linux server, the first thing is to add or remove users. Each user has different permission levels, and specific settings for various command lines and applications.
This article explains how to add and remove users on CentOS 8.
To create or remove users, you need to log in to the system as root or another user with sudo privileges.
On CentOS systems, you can use the useradd
command to create a new user account with the username you want.
For example, to create a new user named "linuxize", you can run:
sudo adduser linuxize
Once successful, this command will not output any prompts. It will create the user and the user's home directory (/home/linuxize
), and copy the files from the /etc/skel
directory to the user's home directory. In the user's home directory, the user can write, edit and delete files and folders.
If you are logged in as root, you do not need to add sudo before each command.
Next, you need to set a password for the new user so that the user can log in. To do this, run the passwd
command with the username:
sudo passwd linuxize
You will be prompted to enter and confirm the password:
Changing password for user linuxize.
New password:
Retype newpassword:
passwd: all authentication tokens updated successfully.
Make sure you use a strong password that contains uppercase and lowercase letters, numbers, and special symbols.
On CentOS system, all members of user group wheel can use sudo
to access.
If you want the newly created user to have administrative rights, add the user to this user group:
sudo usermod -aG wheel linuxize
You can also configure user sudo access rights by modifying the sudoers file.
To delete a user account that is no longer needed, enter the userdel
command and the user name.
For example, to remove a user account named linuxize
, you need to run:
sudo userdel linuxize
Once successful, this command will not produce any output prompts.
The above command will remove the user, but will not delete the user's files. Of course, the user is also deleted from any group he belongs to.
To delete a user, and delete their home directory and mail, run userdel
with -r
option:
sudo userdel -r linuxize
We show you how to add and remove users on CentOS 8. The same command applies to any other Linux distribution.
CentOS, like other Linux distributions, is a multi-user operating system. Knowing how to add and remove users is a basic skill that every Linux user should know.
Original: https://linuxize.com/post/how-to-add-and-delete-users-on-centos-8/
Recommended Posts