Deprecated: Implicit conversion from float 79.9 to int loses precision in /home/holhol2/public_html/wp-includes/class-wp-hook.php on line 85

Deprecated: Implicit conversion from float 79.9 to int loses precision in /home/holhol2/public_html/wp-includes/class-wp-hook.php on line 87

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the js_composer domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/holhol2/public_html/wp-includes/functions.php on line 6121
How to Add a User to a Group in Linux – Holhol24 | Linux Tutorials and Guides

How to Add a User to a Group in Linux

0

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-command-in-linux

getent-command-in-linuxgetent-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-linuxusermod-command-in-linux

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

verify-group-in-linuxverify-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. 

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