Change Group ID in Ubuntu

So, till now we have seen how to create a group and change current effective group in Ubuntu. We take this further and cover how to change the Group ID (GID) itself.

When we create a user, a group is created with the same name as that of user. Such a group is the Primary group for the user. And, the system automatically assigns the next available Group ID (GID) to the group. Apart from that, we can also create groups as and when required. Either we can specify the Group ID at the group creation stage or the system on its own assigns a Group ID.

But, what if we want to modify our Group’s ID for various reasons at later stages. We can do that through groupmod command-line utility.

To check a Group’s ID –

cat /etc/group | grep <group_name>

The numeric third field is the current Group ID.

Note: Following operations require superuser privileges. In case you don’t have one then, we advise you to contact your System Administrator for assistance.

Change Group ID in Ubuntu

Just make sure, the Group ID should be a positive integer value. Besides, Group ID of any files/directories (belonging to the group we act on) previously created should be changed manually. We have covered that part in Change Group ID of a file/directory. For now, we stick we changing a Group’s ID.

So, issue the following in terminal to change Group ID –

sudo groupmod -g <new_Group_ID> <group_name>

or, we can also use –

sudo groupmod --gid <new_Group_ID> <group_name>

Choose either of the above mentioned commands. They both will get us the same outcome.

For instance, if we want to change the current Group ID i.e. 1002 of the Group – techpiezo to 1111. Then, we can use the command as –

sudo groupmod -g 1111 techpiezo

This will change the Group ID of techpiezo group from 1002 to 1111. We can verify the change through the following command –

cat /etc/group | grep techpiezo

In conclusion, we have covered how to change Group ID in Ubuntu.

Similar Posts