In my previous article, I had explained how to create a new group in Linux. Today you will learn how to modify an existing group in Linux using the groupmod command.
groupmod
stands for “Group Modification”.
You have to run the groupmod
command as a root user because upon running this command, it makes changes to the following important configuration files whose owner is root.
- /etc/group
- /etc/gshadow
Table of Contents
Key features of groupmod command:
- Change the name of the group
- Set non-unique Group ID
- Set new Group ID (GID)
- Set Unencrypted Password
First of all, let’s focus on some of the most important options that we can use with the groupmod
.
Options | Explanation |
---|---|
-g, --gid | Change the group ID |
-n, --new-name | Change the name of the existing group |
-o, --non-unique | Allow to use a duplicate (non-unique) GID |
-p, --password | Set Unencrypted Password |
--help | Display help page of grupmod Command. |
You must follow the syntax given below to use the groupmod
command.
groupmod [options] GROUP
1. How to change the name of the group
To change the name of an existing group use the -n
option with the groupmod command.
Here I have a group called linuxadmin
and I want to change the name to linuxadmin_new
# cat /etc/group | grep linuxadmin
linuxadmin:x:1005:
To rename the group name, type the following command.
# groupmod -n linuxadmin_new linuxadmin

Run the following command to verify that the group name has been changed.
# cat /etc/group | grep linuxadmin_new
linuxadmin_new:x:1005:
2. Set new Group ID (GID) for the Group
To change the Group ID of an existing group pass the -g
option to groupmod
command.
As you can see I have a group called linuxadmin_new
with Group ID 1005
.
# cat /etc/group | grep linuxadmin_new
linuxadmin_new:x:1005:
The following command will change the Group ID(GID) from 1005
to 1020
.
# groupmod -g 1020 linuxadmin_new
Type the following command to check the result.
# cat /etc/group | grep linuxadmin_new
linuxadmin_new:x:1020:
3. Set Unencrypted Password for a Group
Issue the following command to set the unencrypted password for a group.
Here I am setting the unencrypted password for a group named linuxadmin_new
.
# groupmod -p [email protected] linuxadmin_new
Type the following command to check the result.
# cat /etc/gshadow | grep linuxadmin_new
linuxadmin_new:[email protected]::
4. Set non-unique Group ID (GID) for a Group
You can have multiple groups with non-unique GID’s(Duplicate GID’s). To assign a non-unique GID to a group use the -o
option with the groupmod command.
I have a group called ayush whose group id is 1108
.
# cat /etc/group | grep ayush
ayush:x:1108:
Now I want to assign the same Group ID to an existing group named linuxadmin_new
. To do this type the following command.
# groupmod -og 1108 linuxadmin_new
Type the following command to check the result.
# cat /etc/group | grep linuxadmin_new
linuxadmin_new:x:1108:
As you can see there are two groups with the same Group ID.
# cat /etc/group | grep 1108
ayush:x:1108:
linuxadmin_new:x:1108:
If you assign a duplicate GID
value without the -o
option, you will get this error.
# groupmod -g 1108 linuxadmin_new
groupmod: GID '1108' already exists
5. Help/Manual page access
Use the following commands to access the Manual Page/Help Page of groupmod command.
# man groupmod
# groupmod --help
You can visit at following websites to get more information on groupmod
.
Conclusion
I hope that now you have a good understanding of how the groupmod command works and you have some ideas for how you can use this within your workflow.
If anyone does have any questions about what we covered in this guide then feel free to ask in the comment section below and I will do my best to answer those.
Here are a few other hand-picked guides for you to read next: