How to Add User to a Group in Linux
Last Updated :
05 Apr, 2025
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:
- 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.
- 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:
- 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. - 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.
Creating a new user and adding it to a groupStep 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:
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.
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.
Checking the user in /etc/passwdHere, 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.
Verifying the user's groupsAs 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.
Similar Reads
How to add multiple users to a group at once in linux?
Managing user groups in Linux is an essential part of system administration. Often, you'll find the need to add multiple users to a specific group simultaneously. This article provides a detailed explanation of how to accomplish this task, covering every aspect, and includes examples for clarity. Un
5 min read
How to Remove All Users From a Group in Linux?
A group is a collection object in the Linux operating system, which associates certain properties and access control to all its members. It is an efficient way for a system administrator to manage Access Control for its users. Groups are an important tool for a system administrator to maintain many
6 min read
How to Remove Users from Groups in Linux?
Groups in Linux are an important part of organizing the system's access control. Creating separate groups for separate types of roles of users allows the administrator to manage the access control of the Linux system efficiently. It is an essential skill to understand how to add, remove, and update
4 min read
How to Check the Groups a User Belongs to in Linux?
This article shows how to check the groups a user belongs to in Linux operating systems. We introduce some concepts related to the topic and then describe how to do so using the groups command available on the terminal. Groups in LinuxAll Linux operating systems are designed as multi-user operating
8 min read
How to Change The Primary Group of a User in Linux?
In the field of Linux system administration, learning the modification of the primary group is essential. In this article, we are going to deliver concise details about user groups and how to manage them. What is a Primary Group?In Linux, every user is associated with a primary group. The primary gr
7 min read
How to Grant Admin Privileges to a User in Linux
Linux is an operating system that is open source operating system. There are many distros available in Linux distribution like Ubuntu, Kali Linux, Arch Linux, and Red Hat Linux. In this article, we will understand how to give admin privileges to non-admin users in the Ubuntu Operating system. Introd
5 min read
How to Rename a Group in Linux?
Renaming a group in a Linux system is a straightforward but essential administrative task. If you're reorganizing your user management structure or enhancing security measures, this quick guide will walk you through the simple steps to rename a group. Linux provides a powerful command, 'groupmod' to
4 min read
How to Add User in Apache Group?
Managing user permissions is a crucial aspect of system administration. When working with Apache on a Linux server, one might need to grant specific users the ability to modify web files or directories. Adding users to the Apache group is an efficient way to manage these permissions. Following are t
3 min read
How To Add User To Docker Group?
Adding the user to the docker group is a common practice adding the user to the docker group allows you to interact with the docker daemon without requiring sudo pervillages. Without adding a user to the Docker group, running Docker commands typically requires superuser privileges. Adding a user to
3 min read
How to add User in Linux | useradd Command
useradd is a command in Linux that is used to add user accounts to your system. It is just a symbolic link to adduser command in Linux and the difference between both of them is that useradd is a native binary compiled with the system whereas adduser is a Perl script that uses useradd binary in the
5 min read