Jump to content

How to Add a User to a Group in Linux


Linux Hint

Recommended Posts

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: 

id prateek

id-command-in-linux

getent group Developer

getent-command-in-linux

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

sudo usermod -aG Developer prateek

usermod-command-in-linux

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

groups prateek

verify-group-in-linux

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. 

View the full article

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...