How to Add a User to a Group in Linux


In Linux, you can create groups to organize users having similar privileges collectively in a single place. Groups allow users to share resources, directory access, permissions, etc. Moreover, if you perform any operation on a group, it applies to all of its members, reducing the time consumed to do it manually for everyone.

However, as a beginner in Linux administrator, it can be sometimes tricky for you to add and modify users in a group. So, this quick guide is about the simple way to create and add a user to a group in Linux.

How to Add a User to a Group in Linux

The usermod is the simplest command to add users to the group. You can also use the usermod to modify user attributes like username, password, home directory, group ID, etc. Here is the example of the usermod to add a group: 

sudo usermod -aG groupID userID

The -a option appends users without removing them from the current group. Meanwhile, the -G option lets you specify the group you want to add the specified user. Please replace user_ID and group_ID with the target user and group name(where you want to add them), respectively. 

So, let’s add a user name, “Prateek,” to the “Developer” group, but first, you need to find the user_ID and group_ID. Hence, you can use the id command for user_ID and getent command for group_ID: 



Now, add these values in the usermod command to add a user to the group: 

sudo usermod -aG Developer prateek


Finally, run the below command to verify whether the user is successfully added in a group: 


A Quick Wrap-up

Groups streamline the process of managing users and their permissions. Users with sudo privileges can perform many operations, such as user add and delete. However, Linux administrators need to understand the basics of the groups. That’s why we have explained a simple command to add a user to a group in Linux. 

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More