In Linux, the group is the set of users that control the permissions of the various users simultaneously. Groups are helpful to manage multiple users in one place. Various users have various responsibilities such as accessing particular files and folders, Linux group facilitates the user to create the categories of users with pre-set permissions.
This blog will present how a specific user can be added to a particular group:
Note: To gain detailed information about creating the users, explore our article on it.
How an Existing User is Added to an Existing Group in Linux?
The “usermod” command is used to add the user to the group. The “usermod” command is utilized for changing the characteristics of the users. Use the following command syntax for adding the user to the group.
$ sudo usermod -a -G [Group Name] [User Name]
Type the “usermod” with sudo privileges, “a” flag for append mode, and “G” flag for a group.
Let’s implement an example for adding the user to the group
List the Available Groups
All groups in Linux are stored in the “/etc/group” file, you can print it for listing the groups. Run the following command to show the file content:
$ less /etc/group
All the available groups have been listed.
Example 1: Adding the User to the Existing Group
To add the existing user to the existing group use the following “usermod” command with “a” and “G” flags:
$ sudo usermod -a -G New_Group Henry
The user “Henry” has been added to the group “New_Group”.
To check the “Henry” user group, use the following command in the terminal:
$ id -Gn Henry
The “Henry” belongs to the “New_Group”.
Example 2: Add the User to Multiple Existing Groups
The user can also add the user to multiple groups, to do so, execute the below-mentioned command:
$ sudo usermod -a -G New_Group,Group2,Group3 HenryUser2
The “HenryUser2” will be added to all 3 groups that are given.
Let’s verify it using the below command:
$ id -Gn HenryUser2
The “HenryUser2” belongs to the 3 groups as shown in the above image.
Common Groups in Linux
There are various types of groups available in Linux, some of the most common groups are given below:
- sudo: sudo group members can use the sudo command to raise their privileges
- wheel: an old method to allow the sudo privileges
- cdrom: This group enables the user to mount the optical drive.
- Adm: this group enables the user to manage the system logs.
- ipadmin: This group grants access to the user for configuring the printers.
- plugdev: this group grants access to the user for external storage devices.
The user can be added to the group using the command “sudo usermod -a -G [Group Name] [User Name]”. Moreover, multiple existing users can be added to an existing group, similarly, a single user can be added to multiple existing groups simultaneously. This write-up has illustrated a detailed explanation of the groups