groupmod Command

The groupmod command modifies existing group accounts on Linux systems. It allows administrators to change group names, group IDs (GIDs), and other group properties.

Syntax

groupmod [OPTIONS] GROUP

Description

The groupmod command is used to modify the properties of existing groups. It's part of the shadow-utils package and requires administrative privileges to execute.

Key features:

  • Change group names
  • Modify group IDs (GIDs)
  • Update group information
  • Maintain system consistency
  • Works with /etc/group and /etc/gshadow files

Common Options

Option Description
-g, --gid GID Change the group ID to GID
-n, --new-name NEW_GROUP Change the group name to NEW_GROUP
-o, --non-unique Allow non-unique GID
-p, --password PASSWORD Set encrypted group password
-R, --root CHROOT_DIR Apply changes in CHROOT_DIR
-P, --prefix PREFIX_DIR Use PREFIX_DIR as prefix

Examples

Change group name

sudo groupmod -n developers programmers

Changes the group name from "programmers" to "developers"

Change group ID

sudo groupmod -g 1500 developers

Changes the GID of the "developers" group to 1500

Change both name and GID

sudo groupmod -n newteam -g 2000 oldteam

Changes group name from "oldteam" to "newteam" and sets GID to 2000

Allow non-unique GID

sudo groupmod -g 1000 -o testgroup

Sets GID to 1000 even if another group already uses this GID

Set group password

sudo groupmod -p '$6$salt$hashedpassword' securegroup

Sets an encrypted password for the group

Verify group changes

getent group developers grep developers /etc/group

Verifies the group modifications

Check group membership

groups username id username

Checks which groups a user belongs to

List all groups

getent group cat /etc/group

Lists all groups on the system

Find files owned by group

find / -group developers 2>/dev/null

Finds files owned by the "developers" group

Update file group ownership

sudo chgrp -R developers /path/to/directory

Changes group ownership of files after group modification

Important Notes

Before Modifying Groups
  • Backup - Always backup /etc/group and /etc/gshadow before making changes
  • Active Users - Ensure no users are actively using the group
  • File Ownership - Consider updating file ownership after GID changes
  • System Groups - Be cautious when modifying system groups (GID < 1000)
  • Dependencies - Check for applications that depend on specific group names or GIDs

See also