RHCSA Rapid Track
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
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
groupnamewithout options uses the next available GID from the range specified in the/etc/login.defsfile.The -g
GIDoption is used to specify a specific GID.[student@serverX ~]$
sudo groupadd -g 5000 ateamNote
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.defsfile.[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 appusersThe -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 javaappA 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 studentAdd a user to a supplementary group with usermod -aG
groupnameusername.[student@serverX ~]$
sudo usermod -aG wheel elvisImportant
The use of the
-aoption 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