4x Affordable, 99.95% SLA, 24x& Video Support, 100+ Countires

Add And Delete Users On A Centos 7 Server


When you first commence using a fresh linux server, increasing and removing users is one of the most basic tasks that you should know how to do. When you create a new server, you are only given the set account by failure. While this gives you a lot of energy and trait, it is also risky to regularly use an account with so much energy; for instance, a set user is more vulnerable to security exploits, since any controls run under that account can affect the server's whole filesystem.

It is almost always a good concept to add an extra, unprivileged user to do communal tasks. You should also create extra accounts for any other users that need accesses to your server. Each user should have an extra account so that their activities can be observed and supervised . You can still acquire administrative rights, when needed, through a mechanism labelled sudo. In this govern, we will cover how to create user accounts, assign sudo rights, and delete users on a centos 7 server.

Adding Users

If you are signed in as the set user, you can create a new user at any moment by writing :

adduser username

If you are signed in as a non-set user who has been given sudo rights, as shown in the next part of this tutorial, you can add a new user by writing :

sudo adduser username

Next, you'll need to give your user a password so that they can log in. To do so, use the passwd command:

passwd username

Note: Remember to add sudo ahead of the command if you are signed in as a non-set user with sudo rights.

You will be prompted to symbol in the password twice to confirm it. Now your new user is set up and prepared for use! You can now log in as that user, using the password that you set up.

Granting Sudo Privileges to a User

If your new user should have the ability to kill regulates with set (administrative) rights, you will need to give the new user accesses to sudo.

We can do this by increasing the user to the wheel faction (which gives sudo accesses to all of its members by failure) through the gpasswd command. This is the fail-safe and simple route to supervise sudo user rights.

If you are currently signed in as the set user, symbol:

gpasswd -a username wheel

If you are signed in using a non-set user with sudo rights, symbol this instead:

sudo gpasswd -a username wheel

Now your new user is able to execute commands with administrative rights. To do so, simply type sudo ahead of the command that you want to kill as a fiduciary:

sudo some_command

You will be prompted to enter the password of the orderly user account that you are signed in as. Once the correct password has been referred , the command you entered will be killed with set rights.

Managing Users with Sudo Privileges

While you can add and remove users from a faction (such as wheel) with gpasswd, the command doesn't have a path to show which users are members of a team. In order to see which users are part of the wheel team (and thus have sudo rights by failure), you can use the lid function. lid is normally used to show which factions an user belongs to, but with the -g flag, you can reverse it and show which users be in a faction:

sudo lid -g wheel

The production will show you the usernames and UIDs that are associated with the team. This is a good path of confirming that your preceding controls were boffo, and that the user has the rights that they need.

Deleting Users

If you have an user account that you no longer need, it's best to delete the old account. You have a couple of modes to do so, though the decision of which mode to use depends on your own situation.

If you want to delete the user without erasing any of their records, symbol this command as set:

userdel username

If you want to delete the user's environment directory along with the user account itself, symbol this command as set:

userdel -r username

Note: Remember to add sudo ahead of the command if you are signed in as a non-set user with sudo rights.

With either command, the user will automatically be removed from any factions that they were increased to, including the wheel faction if they were given sudo rights. If you later add another user with the same name, they will have to be added to the wheel faction again to earn sudo accesses.


You should now have a good grasp on how to add and remove users from your CentOS 7 server. Effective user management will allow you to apart users and give them only the accesses that is needed for them to do their job. You can now move on to configuring your CentOS 7 server for whatever program you need, such as a LAMP or LEMP web stack.

For more information about how to configure sudo, check out our govern on how to edit the sudoers register.

Reference: digitalocean