How to Add a User to a Group in Debian 12

Groups in Debian 12 are made to organize the users. Users in the one group have the same privileges which help them complete their specific tasks and this ensures the security of the data as well as controls the accessibility of the data. 

When the users are added to the groups, their roles and responsibilities are well defined, for example, the group of developers will take part only in development tasks. Similarly, the administrative group members will handle the administrative tasks. 

This post will explain the step-by-step guide to add the users in groups in Debian 12 using the terminal. 

What is the Method to Add the User in the Existing Group in Debian 12?

To add the users to the already created group, use the below-mentioned steps. 

Step 1: Verify the Group

First, verify the group’s existence with the command:

$ grep itslinuxfoss /etc/group

The output confirms the existence of the group “itslinuxfoss” in Debian 12.

Step 2: Create a New User

A user in Debian 12 can be created by following the blog. For example, the user “paul” is created:

$ sudo adduser paul

Step 3: Add the User to the Existing Group

Now add the new user to the “itslinuxfoss” group by running the command:

$ sudo usermod -a -G itslinuxfoss paul

In the above command, the “a” option is used to add the user “paul” to the group without changing the other member’s privileges. The “G” option specifies the group in which the user is added. 

Step 4: Confirm the Addition of the User to the Existing Group

Finally confirm the addition of the user, “paul” in the group “itslinuxfoss”:

$ id paul

The output displays that the user “paul” is a member of the “itslinuxfoss” group. 

What is the Method to Add the User in the New Group in Debian 12?

Sometimes, a new group is required to create and add users to it. For this purpose, the mentioned-below instructions should be followed. 

Step 1: Create a New Group

Create a new group with the name “mynewgroup”:

$ sudo groupadd mynewgroup

Step 2: Verify the New Group

Verify the creation of the new group:

$ grep mynewgroup /etc/group

Step 3: Add the User

Now add the user “paul” to the “mynewgroup”:

$ sudo usermod -a -G mynewgroup paul

Step 4: Verify the Addition of the User

Finally, display the identity of the “paul” user:

$ id paul

How to Remove a User from a Group in Debian 12?

A user in Debian 12 can be removed from a group in Debian 12, using the “deluser” command. For example, to remove the user “paul”, run the command:

$ sudo deluser paul itslinuxfoss

After the successful execution of the above command, the user paul will be removed from the itslinuxfoss group. This can be verified by running the command:

$ id paul

This is all about adding the user to a group in Debian 12. 

Conclusion

To add the user to the group, run the command “sudo usermod -a -G [Group Name] [User]” in Debian 12. Similarly, to remove the user from the group, use the deluser command. In this post, the step-by-step method of adding the user to an existing and newly created group has been explained. Also, the method of removing the user from the group is demonstrated.