LinuxCommandLibrary

groupmod

Modify group attributes

TLDR

Change the group name

$ sudo groupmod [[-n|--new-name]] [new_group] [group_name]
copy

Change the group ID
$ sudo groupmod [[-g|--gid]] [new_id] [group_name]
copy

SYNOPSIS

groupmod [OPTIONS] GROUP

PARAMETERS

-g GID, --gid GID
    Changes the group ID (GID) to the specified value.

-n NEW_GROUP, --new-name NEW_GROUP
    Changes the group's name to the new specified name.

-o, --non-unique
    Allows the new group ID to be non-unique, enabling duplicate GIDs.

-R CHROOT_DIR, --root CHROOT_DIR
    Applies changes in the specified chroot directory instead of the system root.

-P PREFIX_DIR, --prefix PREFIX_DIR
    Applies changes in the specified prefix directory (used by shadow utilities).

-h, --help
    Displays a help message and exits the command.

DESCRIPTION

The groupmod command is used to modify an existing group's definition on a Linux system. It allows administrators to change a group's name or its Group ID (GID). When changing the group name, all entries referencing the old name in system files like /etc/group and /etc/gshadow are updated. Similarly, changing the GID updates these files. This command is crucial for maintaining proper group management, especially in environments where group identifiers or names need to be adjusted without recreating the group and reassigning its members. It automatically handles updates to the necessary system configuration files. Note that changing a GID does not automatically update the ownership of files belonging to that group; this requires a separate command like chgrp.

CAVEATS

When changing a group's GID, groupmod does not automatically update the GID of files owned by that group. This must be done manually using commands like chgrp and find. Processes running under the old GID will continue to do so until they are restarted. Using the --non-unique option can lead to issues with file permissions and security as multiple groups might share the same GID.

FILE OWNERSHIP UPDATE

When a group's GID is changed, the ownership of files and directories that belong to that group is not automatically updated. An administrator must manually update these using commands such as find / -gid OLD_GID -exec chgrp -h NEW_GID {} \; to ensure consistency across the filesystem. Note the escaped semicolon in the example command.

PROCESS GID

Running processes that are associated with the group's old GID will continue to run with that old GID until they are restarted. This is an important consideration for system services or long-running applications affected by a GID change.

HISTORY

groupmod is a part of the `shadow-utils` package, which provides essential utilities for managing user and group accounts on Linux and Unix-like systems. These tools have been a fundamental component of system administration for decades, evolving to support modern security practices like shadowed passwords and GIDs, ensuring robust and secure account management.

SEE ALSO

groupadd(8), groupdel(8), usermod(8), gpasswd(1), chgrp(1)

Copied to clipboard