close
close
ABOUT US AFFIALITES CONTACT US LOGIN CLIENT AREA
menu
+3197010282575 We also take care of providing excellent support 24/7 at no additional cost.

BLOGS

How to add or remove a user on your Linux server

02.06.2024

In this guide, we will explain how to add and remove a user on your Linux server. There are small differences in the different Linux distributions. With Red Hat based distributions you will not be prompted to enter a password. With Debian based distributions you will be prompted to enter a password. You are also prompted to enter personal data for the new user with Debian based systems.

How to add or remove a user on your Linux server

In this guide, we will explain how to add and remove a user on your Linux server. There are small differences in the different Linux distributions. With Red Hat based distributions you will not be prompted to enter a password. With Debian based distributions you will be prompted to enter a password. You are also prompted to enter personal data for the new user with Debian based systems.

Add a user

In this example, we will create a new user called offshoreserver. We can create this user by using the following command:

[root@offshoreserver ~]# adduser offshoreserver

On a Red-Hat based system, you will not automatically be prompted for a password. In order to set the password you can use the following command:

[root@offshoreserver~]# passwd offshoreserver

Add and remove a user from the sudo group

When you have created a new user you can also add the user to the sudo group. On Debian based systems this is done with the following command:

[root@offshoreserver ~]# usermod -aG sudo offshoreserver

If you are using a Red-Hat based system you can achieve the above with the following command:

[root@offshoreserver ~]# usermod -aG wheel offshoreserver

If you want to remove a user from the sudo group on a Debian based system you can use the following command:

[root@offshoreserver ~]# gpasswd -d offshoreserver sudo

In case you want to remove a user from the sudo group on a Red-Hat based system you can use the following command:

[root@offshoreserver ~]# gpasswd -d offshoreserver wheel

Remove a user

In order to remove a user the following command can be used:

[root@offshoreserver ~]# userdel offshoreserver

Do note with removing users this way that the home directory of the user will not be automatically removed. In case you also wish to remove the home directory of the user please use the -r option with the userdel command. This option will also remove the user’s mail spool. Below is an example of this command.

[root@offshoreserver ~]# userdel -r offshoreserver

Conclusion

In this guide, we have shown you some of the basics with user accounts.  Adding, modifying, and removing users can come in handy when you have just received your new server. This guide will provide some steps to get started with new users on your system. Keep in mind that some commands may vary with other Linux distributions.