How to Create a new group in Linux | groupadd command
In the Linux operating system, user management is a crucial aspect of system administration. One of the fundamental tasks is creating and managing user groups. Groups in Linux allow administrators to organize and control user access to various resources and files. The groupadd
command is a powerful tool that facilitates the creation of new groups effortlessly. In this article, we will delve into the details of using the groupadd
command to create a new group in Linux.
Table of Content
Understanding User Groups
Groups in Linux refer to the user groups. In Linux, there can be many users of a single system, (a normal user can take uid from 1000 to 60000, and one root user (uid 0) and 999 system users (uid 1 to 999)). In a scenario where there are many users, there might be some privileges that some users have and some don’t, and it becomes difficult to manage all the permissions at the individual user level. So, using groups, we can group together a number of users, and set privileges and permissions for the entire group.
Before we dive into the practical aspects, let’s briefly understand the concept of user groups in Linux. A group is a collection of users with similar permissions or access levels. Groups make it easier to manage and assign permissions to multiple users at once, enhancing security and simplifying administrative tasks.
Syntax of the `groupadd` Command
The `groupadd`
command follows a simple syntax:
groupadd [options] group_name
Here,
- ‘group_name‘: This is the name of the group you want to create.
- ‘[options]’: These are various flags that allow customization of the group creation process, such as specifying a Group ID (GID), setting a password, or creating system groups.
How to create a new group in Linux
Follow these steps to create a new group in Linux using the groupadd command:
1. Open a terminal
Launch a terminal on your Linux system. This can usually be done by pressing `Ctrl + Alt + T`
or searching for “Terminal” in the application menu.
2. Use the `groupadd`
command:
To create a new group, type the following command in the terminal:
Example:
If we want to create a group named “developers”, we can use the following command.
sudo groupadd developers
Replace “mygroup” with the desired name for your new group. The sudo
command is used to execute the groupadd
command with administrative privileges.
3. Verify the creation of the new group:
Every new group created is registered in the file “/etc/group“. To verify that the group has been created, enter the command.
sudo tail /etc/group

sudo tail /etc/group
The file shows group information in the following format:
group_name : password : group-id : list-of-members
Options Available with`groupadd` command
The ‘groupadd‘ command provides several options to customize the group creation process. Here are some of the most commonly used options:
Options | Description |
---|---|
-f, –force |
|
-g GID, –gid GID |
|
-h, –help |
|
-K KEY=VALUE, –key KEY=VALUE |
|
-o, –non-unique |
|
-p PASSWORD, –password PASSWORD |
|
-r, –system |
|
-R CHROOT_DIR, –root CHROOT_DIR |
|
Practical Examples to Create New Group in Linux Using Options Available
1. Using`-f, –force` option to Create New User.
Syntax:
groupadd -f developers

groupadd -f developers
2. Specifying a Group ID to Create New User
If we want to assign a specific group id to the newly created group, use the ‘-g’ option.
Syntax:
sudo groupadd -g 1001 developers
This command will create a new group named “developer” with a GID of 1001. Specifying group ID is useful in case where we need to maintain consistency across systems.
3. Setting a Group Password
We can set an encrypted password for a group using the ‘-p’ option.
Syntax:
sudo groupadd -p somepassword finance
This command creates a new group named “finance” and sets the password for the group as “somepassword”
4. Overriding Default Values
Suppose we want to modify the ‘GID_MIN’ and ‘GID_MAX’ values for a group creation. We can achieve this using the ‘-K’ option
Syntax:
groupadd -K GID_MIN=500 -K GID_MAX=700 tester

groupadd -K GID_MIN=500 -K GID_MAX=700 tester
This command will create a new group named “tester” and set the minimum GID to 500 and the maximum GID to 700. This allows us to have finer control over the range of valid group IDs for the created group.
5. To Create a new user into the group, the group is mentioned using -g option in the command useradd.
Syntax:
sudo useradd -g developers new_user
6. To add an existing user to a group, use the usermod command
Syntax:
usermod -g developers existing_user

usermod -g developers existing_user
Conclusion
In this article we have discussed `groupadd` command. By understanding and utilizing the options we have discussed in the ‘groupadd’ command, we can effectively manage group IDs, create system groups, set group passwords, and customize default value according to our specific requirements and security policies.
How to Create a new group in Linux | groupadd command – FAQs
How can I check if a group has been successfully created?
You can verify the successful creation of a group by checking the “/etc/group” file or by using the `
getent`
command.For example: running `
getent group group_nam
e`
should display information about the newly created group, including its name and Group ID (GID).
What is the difference between a regular group and a system group created with the groupadd command using the -r option?
The `
-r`
option in the `groupadd`
command is used to create a system group. System groups typically have lower Group IDs (GID) and are reserved for system processes and services. Creating a system group is often recommended for enhanced system security and to prevent accidental modification or removal by regular users.
What happens if I try to create a group with a name that already exists?
If you attempt to create a group with a name that already exists, the
groupadd
command will typically return an error, stating that the group already exists. To avoid this, you may use the `-f`
option to force the creation of the group, though caution should be exercised to prevent unintentional overwriting of existing groups.
How can I specify a Group ID (GID) when creating a new group with the groupadd command?
Yes, the `
groupadd`
command allows you to specify a Group ID using the `-g`
option. This can be useful for maintaining consistency in user and group management, especially in environments with specific GID requirements.
What is the purpose of creating a new group in Linux using the groupadd command?
The primary purpose of creating a new group in Linux is to organize and manage users with similar permissions. Groups enable administrators to assign common access levels to multiple users, facilitating efficient resource management and enhancing system security.