Modify a group name, password, GID, or members using the GROUPMOD command in Linux

Home > Search > Linux commands
  by

 

The /etc/group file contains a list of groups on the system. The records in the /etc/group file will contain 4 fields. The 4 fields are: group name:password:GID:group members.

[root@server1 ~]# cat /etc/group
group1:x:1001:

 


Change group name

The -n or --new-name option can be used to change the name of a group. For example, to change the group name from group1 to group2:

[root@server1 ~]# groupmod -n group2 group1

 

The /etc/group file will now have group2 as the group name.

[root@server1 ~]# cat /etc/group
group2:x:1001:

 


Add or change group password

The -p or --password option can be used to add or change the password for the group. Adding or changing a group password using the groupadd or groupmod commands will create an unencrypted, cleartext password. Adding or changing a group password using the gpasswd command will create an encrypted password.

[root@server1 ~]# groupmod -p Password123 group1

 

Similarly, the gpasswd groupname command can be used to secure a group with an encrypted password.

Regardless if the group is or is not secured with a password, the second field of /etc/group will display an "x", so viewing the /etc/group file does not help to know if the group is secured with a password.

[root@server1 ~]# cat /etc/group
group1:x:1001:

 

The /etc/gshadow file will contain the group password.

[root@server1 ~]# cat /etc/gshadow
group1:Password123::

 


Change GID

The -g or --gid option can be used to change the GID of a group. For example, to change the GID of group1 from 1001 to 1234.

[root@server1 ~]# groupmod -g 1234 group1

 

Group1 will now have GID 1234.

[root@server1 ~]# cat /etc/group
group1:x:1001:

 

By default, the system expects each group to have a unique GID. When attempting to change the GID to a GID already in use, an error will appear.

[root@server1 ~]# groupadd -g 1234 group2
groupmod: GID '1234' already exists

 

The -o or --non-unique option can be used to create a new group using a GID already being used by another group.

[root@server1 ~]# groupadd -og 1234 group2

 

In this example, there will now be two groups with GID 1234.

[root@server1 ~]# cat /etc/group
group1:x:1234:
group2:x:1234:

 


Add group members

There is no option to add members to a group with the groupmod command. The usermod command can be used to add members to a group.



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments