Debian

How to Add a User to a Group in Debian 10?

Every operating system works on the concept of privileges. These privileges are the rights that are granted to each user based on the permissions they have and the tasks that they want to perform. These permissions can include the following: Read, Write, and Execute. Ideally, no operating system should allow a user to escalate the privileges that are once assigned to him unless they are changed by the operating system. Hence, each user can only perform the functions that are specified in his privileges.However, at times, multiple users have the same privileges for the same resource. This is the situation where the concept of Group comes into play. In the Linux operating system, a group is defined as a set of different users who have the same privileges. It means that when multiple users tend to have the same privileges, then instead of granting those privileges to each user separately, we create a group with the desired privileges and add all the concerned users to that group so that all of them can have the same privileges.

Groups can essentially have the following two types:

  • Primary Group
  • Secondary Group

The point to be noted here is that a user can be a part of one and only one Primary group, whereas he can be a part of more than one Secondary group. Therefore, in this article, we are going to explain to you the methods with which you can add a user to a group or groups in Debian 10.

Methods of Adding a User to a Group in Debian 10:

To add a user to a group or groups in Debian 10, you can make use of any of the two methods discussed below:

Method # 1:

In this method, we are going to explain to you how you can add a user to a single group at a time. For doing that, you will need to perform the following steps:

1. Click on the Activities tab located on your desktop as highlighted in the image shown below:

2. As soon as you will do this, a search bar will appear on your screen. Type terminal in that search bar and click on the search result to launch the terminal in Debian 10 as highlighted in the following image:

3. Doing this will launch the terminal window, which is shown in the image below:

4. Now type the following command in your terminal and then press the Enter key:

sudo usermod –a –G GroupName UserName

Here, replace GroupName with the name of the group to which you want to add the user and UserName with the name of the user whom you want to add in the group. In this example, I wanted to add the user KBuzdar to the sudo group. Therefore, I have replaced GroupName with sudo and UserName with KBuzdar. As soon as this command executes successfully, the specified user will be added to the specified group. This command is also shown in the following image

Method # 2:

In this method, we are going to explain to you how you can add a user to multiple groups at the same time. For doing that, you will need to perform the following steps:

Launch the terminal in the same way as described in the method above. Now type the following command in your terminal and then press the Enter key:

sudo usermod –a –G GroupName,GroupName UserName

Here, you can add as many groups as you want, separated by a comma, as shown above. Replace GroupName[s] by the names of all the groups to which you want to add your user and UserName with the name of the user that you want to be added to the specified groups. In this example, I wanted to add the user KBuzdar to the sudo and docker groups. Therefore, I have replaced GroupName[s] with sudo and docker and UserName with KBuzdar. As soon as this command executes successfully, the specified user will be added to the specified groups. This command is also shown in the image below:

Conclusion:

By following the two methods described in this article, you can conveniently add a user to a group or even multiple groups at a time. In this way, you will not have to grant each user with the same privileges separately; rather, they will automatically be granted to them once they become a part of a certain group. This will not only save your precious time but will also increase your productivity.

About the author

Karim Buzdar

Karim Buzdar

Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. You can reach Karim on LinkedIn.