Use
groupmod command in linux is used to modify the information related to any existing group.
Syntax
groupmod [options] GROUP
Options used with groupmod command in linux.
1. Change the GID of the group
-g : option changes the group ID of the group. But, the value specified must be unique and non-negative.
For Example: An existing group in the system G1 has the group ID 983.
![Before -g option with groupmod command in linux](https://dextutor.com/wp-content/uploads/2019/10/before-g.jpg)
Next, We use -g option with groupdel to change the group ID of G1 from 983 to 9000.
![-g option with groupdel command in linux](https://dextutor.com/wp-content/uploads/2019/10/g.jpg)
2. Change the group name
-n : option changes the group name to a new one.
For Example: There exists group G1 having GID 9000 as highlighted in figure below.
![Before -n option with groupmod](https://dextutor.com/wp-content/uploads/2019/10/before-n.jpg)
Now, we change the name from G1 to Group1 (the GID remains the same).
![](https://dextutor.com/wp-content/uploads/2019/10/n.jpg)
3. To have non-unique GID
-o : option allows having non unique GIDs. Remember, this option can be used along with -g option only.
For Example: There are two groups in my system – Group1(having GID 9000) and Group2(having GID 9001).
![Before -g option with groupmod](https://dextutor.com/wp-content/uploads/2019/10/before-o.jpg)
Next, we change the GID of Group2 to 9000. After this change both Group1 and Group2 will have the same GID i.e., 9000.
![-o option with groupmod](https://dextutor.com/wp-content/uploads/2019/10/o.jpg)
4. Set password
-p : options sets the password. But, this option is not recommended as the password will be visible to users.
Files related to groupmod command in linux
/etc/group – contains the information about the groups in the system. Thus, you can view the contents of this file to check whether a group is there in the system or not.
/etc/gshadow – contains the secure information about the groups in the system
/etc/login.defs – Shadow password suite configuration file
/etc/passwd – contains information about user account. Thus, you can view the contents of this file to check whether a user is there in the system or not.
Related commands
Some useful questions
Q1. What is/are the benefit(s) of having same GID with -o option for multiple groups?
Q2. If the group ID of any group is changed with -g option then what happens to the files belonging to that group?