
groupmod Command in Linux
groupmod is a Linux command that is used to modify the properties of an existing group on the system. With the help of this command, you can change the groups name, group ID (GID), and other attributes. For example, you can rename a group or assign a new GID to it.
The groupmod command can only be run by the root user or a user having sudo privileges.
Table of Contents
Here is a comprehensive guide to the options available with the groupmod command in linux −
Syntax of groupmod Command
The general syntax to use the groupmod command in Linux is as follows −
groupmod [options] group_name
Where,
- [options] specifies different flags that you can use to change your group modification process.
- group_name is the name of the group that you want to modify.
groupmod Command Options
With the groupmod command, there are few options that you can use, which are discussed in the table provided below −
Option | Description |
---|---|
-a, --append | Add a user to the group. |
-g, --gid GID | Change the group ID (GID) to the specified value. |
-h, --help | Display help information about the groupmod command. |
-n, --new-name NEW_GROUP | Rename the group to the new specified name. |
-o, --non-unique | Allow the new GID to be non-unique (duplicate GID). |
-p, --password PASSWORD | Change the group password. |
-R, --root CHROOT_DIR | Implement modifications within the designated chroot directory. |
-P, --prefix PREFIX_DIR | Implement changes with the specified prefix directory. |
-U, --users USERS | Specify users to be added to the group. |
Examples of groupmod Command in Linux
Lets explore a few practical examples of groupmod command in Linux system −
- Changing the Group ID (GID)
- Renaming a Group
- Allowing Non-Unique GID
- Changing the Group Name
- Setting a Password for a Group
Changing the Group ID (GID)
You can use the groupmod command to change the GID of an existing group. This can be useful in case you need to align group IDs across different systems. Heres an example that changes the GID of the developers group to 1007 −
sudo groupmod -g 1007 developers

To confirm the GID change, you can use the following command −
grep 'developers' /etc/group
Renaming a Group
In case you want to rename an existing group, simply use the groupmod command with -n option. This is useful if the group purpose has changed or you need a more descriptive name for your group. For example, to rename the developers group to dev_team, you can use the following command −
sudo groupmod -n dev_team developers

Allowing Non-Unique GID
Sometimes, you might need to assign a GID that is already in use by another group, the -o option allows this. Heres an example that changes the GID of the dev_team group to 1001, even if another group already has this GID −
sudo groupmod -o -g 1001 dev_team

Changing the Group Name and GID Simultaneously
You can change both the group name and GID in a single command. For example, to rename the developers group to dev_team and change its GID to 1002 −
sudo groupmod -n dev_team -g 1002 developers
Note − Make sure to check that the new GID (1002 in this case) is not already in use by another group to avoid conflicts.
Setting a Password for a Group
Although not commonly used, you can also modify your password for a group to further improve the security for group access. Heres an example −
sudo groupmod -p your_password dev_team

Thats how you can use the groupmod command on Linux systems.
Conclusion
The groupmod command is a versatile tool used in Linux for modifying existing user groups. Thus, helps you in efficient management of permissions and access for multiple users. This tutorial has explored the syntax, various options and practical examples of using the groupmod command.
Whether you need to update group names, assign new GIDs, or apply changes in a chroot environment, this command offers the flexibility to meet your systems requirements.