Bookmark this page

Managing Local Group Accounts

Manage local groups with command-line tools.

Objectives

After completing this section, students should be able to create, modify, and delete locally defined group accounts.

Managing supplementary groups

Managing local groups

A group must exist before a user can be added to that group. Several command-line tools are used to manage local group accounts.

groupadd creates groups

  • groupadd groupname without options uses the next available GID from the range specified in the /etc/login.defs file.

  • The -g GID option is used to specify a specific GID.

    [student@serverX ~]$ sudo groupadd -g 5000 ateam

    Note

    Given the automatic creation of user private groups (GID 1000+), it is generally recommended to set aside a range of GID numbers to be used for supplementary groups. A higher range will avoid a collision with a system group (GID 0-999).

  • The -r option will create a system group using a GID from the range of valid system GID numbers listed in the /etc/login.defs file.

    [student@serverX ~]$ sudo groupadd -r appusers

groupmod modifies existing groups

  • The groupmod command is used to change a group name to a GID mapping. The -n option is used to specify a new name.

    [student@serverX ~]$ sudo groupmod -n javaapp appusers
  • The -g option is used to specify a new GID.

    [student@serverX ~]$ sudo groupmod -g 6000 ateam

groupdel deletes a group

  • The groupdel command will remove a group.

    [student@serverX ~]$ sudo groupdel javaapp
  • A group may not be removed if it is the primary group of any existing user. As with userdel, check all file systems to ensure that no files remain owned by the group.

usermod alters group membership

  • The membership of a group is controlled with user management. Change a user's primary group with usermod -g groupname.

    [student@serverX ~]$ sudo usermod -g student student
  • Add a user to a supplementary group with usermod -aG groupname username.

    [student@serverX ~]$ sudo usermod -aG wheel elvis

    Important

    The use of the -a option makes usermod function in "append" mode. Without it, the user would be removed from all other supplementary groups.

References

group(5), groupadd(8), groupdel(8), and usermod(8) man pages

Revision: rh124-7-1b00421