Open In App

How to Add User to a Group in Linux

Last Updated : 05 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

A group in Linux is a way to put users with similar access and permissions in a collection. By using groups, an administrator can define access control and permissions for all the users belonging to that group. Without groups, the administrator would have to define roles for individual users however, with groups those roles can be given to a group which in turn, will apply to all the users in the group.

In this article, we shall learn how to add a user to a group. We shall see different methods to do the same.

What is Linux Group?

A Linux group is a collection of user accounts that share common access permissions to files, directories, and other system resources. Each user on a Linux system is associated with one or more groups, and groups are used to simplify the process of managing user access and privileges.

Key Characteristics:

  1. Group Identifier (GID): Each group is assigned a unique numerical identifier known as the Group ID (GID). The GID is used by the system to differentiate between groups and is associated with specific permissions.
  2. Group Membership: Users can belong to one or more groups. When a user is part of a group, they inherit the permissions assigned to that group. This simplifies the process of managing permissions for multiple users who require similar access levels.

Types of Groups:

  1. Primary Group: Every user has a primary group, which is the main group associated with their account. The primary group is specified in the user's entry in the /etc/passwd file.
  2. Secondary Groups: Users can also belong to additional groups known as secondary groups. These groups provide supplementary permissions beyond those granted by the primary group.

Pre-requisites to Add a User to a Group in Linux

How to Add User to a Group in Linux While Creating the User.

Step 1: Creating a user while adding it to a group.

We can create a user with the useradd command.

useradd [options] [username]

We can use the -G option followed by the group name to add this user to any group we want. For example, we shall create a user 'dummy' and add it to the sudo group with the following command.

useradd -G sudo dummy

This would create the user and simultaneously add it to the sudo group.

Picture4
Creating a new user and adding it to a group

Step 2: Verifying the groups of the user 'dummy'.

To check the groups of user dummy, we can use the groups command.

#syntax
groups [username]

Type the following command in the terminal.

groups dummy

Output:

Picture5
Checking groups of dummy user.


As we can see, the dummy group is now a member of the sudo group.

How to Add User to a Group in Linux Which Already exist.

In this method, we shall create a new user for demonstration purposes. Then, we shall add it to an already existing group.

Step 1: Creating a user(Optional)

We shall create a test user using the useradd command. This command is used to add users to the linux system.

useradd geek

Here, we are using the username as geek. You are free to use any name of your choice.

Picture1
Adding geek user to the system


Now, to verify whether the user ahas been added or not, use the following command.

cut -d: -f1 /etc/passwd | grep 'geek

The cut command gets content from the file based on the condition given. Here

  • We are selecting the first field with option -f1.
  • The fields are divided by the delimites : passed with -d.
  • We access the /etc/passwd file which contains all the users that exists in the system. (You need either root or sudo access to read this file)
  • Then, we grep our user name 'geek' to see if it is added to the users list.
Picture2
Checking the user in /etc/passwd

Here, we are getting the output geek which means that user has been added successfully.

Step 2: Adding the created user to the sudoers group

Now, to add any user to a group, we have the usermod command which is for user modification.

The syntax is:

usermod [options] [other fields...] [username]

Here, we will use the -aG option which means append to group then the first argument after the -aG option we will pass the group name and then, finally the username.

In order to add the geek user to sudo group, we need the following modifications:

usermod -aG sudo geek

Once, this command is executed. You can check all the groups that the geek user belongs to by using the groups command.

groups geek

This will list all the groups that the user 'geek' is a member of.

Picture3
Verifying the user's groups

As we can see, the geek user belongs to 2 groups, geek(every user gets a group of its own name) and sudo. Thus, we successfully added the user geek to sudo group.

Also Read: How to add multiple users to a group at once in linux?

Conclusion

Adding members to groups within Linux is a basic yet required step toward successful system administration. Linux groups make managing permissions and access control easy, so users belonging to the same group have equal access to directories, files, and system resources.

By using Group IDs (GID) and placing users into primary and secondary groups, administrators can easily assign or modify user permissions in bulk and bypass the inconvenience of working with single accounts. Through the use of commands such as useradd and usermod, placing users on existing or new groups can be effectively done, providing secure and methodical system administration.

Regardless of whether handling a server, maintaining a business network, or setting up one Linux system, mastery of group management is vital to ensuring security, efficiency, and tidiness in user permissions.


Next Article

Similar Reads