How to Use the groupmod Command in Linux to Rename User Groups

As a Linux server environment evolves, departmental roles often shift, and naming conventions change. If an administrative group currently named “it-staff” needs to be updated to “devops,” deleting the old group and creating a new one from scratch is highly destructive. Deleting the group orphans all files owned by it, forcing the administrator to manually reassign permissions across the entire filesystem. Instead, you can safely rename an existing group while perfectly preserving all file ownerships by using the groupmod command.

Why Use the groupmod Command?

The groupmod utility directly modifies the system’s /etc/group file to alter a group’s name or its numeric Group ID (GID). When you use groupmod to rename a group, the underlying GID remains completely unchanged. Because the Linux filesystem tracks file ownership using numeric GIDs rather than text-based group names, all existing files immediately inherit the new group name automatically, with zero risk of permission errors.

Step 1: Verify the Current Group Name

Before modifying a group, verify its current name and GID.

  1. Open your Linux terminal.
  2. Use the grep command to search the group database:
grep "it-staff" /etc/group

The terminal will output the group record (e.g., it-staff:x:1005:), confirming the group exists and showing its numeric GID.

Step 2: Rename the Group

Modifying system groups requires root privileges, so you must use sudo.

  1. To rename the group from “it-staff” to “devops”, use the -n (new name) flag.
  2. The syntax requires the new name first, followed by the old name:
sudo groupmod -n devops it-staff

The command will execute silently. If no error is returned, the group has been successfully renamed.

Step 3: Change a Group ID (Optional)

In rare cases, such as merging network directories across different servers, you may need to change the actual numeric GID rather than the name.

  1. To change the GID of the “devops” group to 2050, use the -g flag:
sudo groupmod -g 2050 devops

Warning: Unlike renaming the group, changing the GID will break existing file ownerships. If you change the GID, you must use the find and chgrp commands to manually hunt down and reassign ownership to all files previously owned by the old GID.

Step 4: Verify the Changes

Always double-check that the modification was successful.

  1. Run the grep command again using the new name:
grep "devops" /etc/group

The output will confirm that the new name is mapped to the original GID.

By using the groupmod command, system administrators can cleanly update organizational structures without breaking the underlying security and permission models on the Linux filesystem.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.