In this article, we want to teach you how to create and delete users on centos 7. It is the most basic task that you should know about.
How to create and delete users on CentOS 7
Create a user on CentOS 7
You can create a user as a root user any time you want with the following command:
Note: if you are a non-root user with accessing root privileges you can use sudo before each command:
sudo adduser username
Now you need to set a password for your new user. You can do it with the following command:
Note: remember to use sudo privileges if you are a non-root user.
Give sudo privileges to a user on Centos 7
If a user on CentOS 7 wants to use a command with root privileges, the user should have access to sudo privileges.
Sudoers are in a group named “wheel”, they have access to root privileges.
You can add a user in “wheel” to have sudo access with the following command:
gpasswd -a username wheel
If you are a non-root user use sudo privileges:
sudo gpasswd –a username wheel
Now your new user has access to root privileges.
With the lid command, you can see that your user is in which group, and with the –g switch you can see which users are in that group. In your output, you can see usernames and UIDs.
lid username lid –g wheel
Delete a user on Centos 7
If you don’t want your user anymore you can run the following command:
Note: this command will not delete the home directory. If you want to delete the home directory too use the –r switch:
userdel –r username
As we mention before remember to use sudo before each command if you are a non-root user to have access to the root privileges.
Now you can easily add/delete and manage the root privileges for users.
Hope you enjoy this article about How to create and delete users on CentOS 7.
For more articles, you can visit the orcacore website.