After completing this section, you should be able to:
- Create, modify, and delete local group accounts.
-
Create a New Group:
groupadd groupname
- Uses the next available GID from the range specified in the
/etc/login.defs
file.
- Uses the next available GID from the range specified in the
-
Specify a GID for the Group:
groupadd -g GID groupname
- Example:
sudo groupadd -g 10000 group01 tail /etc/group
- Example:
Note:
-
Automatic creation of user private groups (GID 1000+) means it is recommended to set aside a range of GIDs for supplementary groups to avoid collision with system groups (GID 0-999).
-
Create a System Group:
groupadd -r groupname
- Uses a GID from the range of valid system GIDs listed in
/etc/login.defs
. - Example:
sudo groupadd -r group02 tail /etc/group
- Uses a GID from the range of valid system GIDs listed in
-
Change Group Name:
groupmod -n newgroupname oldgroupname
- Example:
sudo groupmod -n group0022 group02 tail /etc/group
- Example:
-
Change GID:
groupmod -g newGID groupname
- Example:
sudo groupmod -g 20000 group0022 tail /etc/group
- Example:
- Remove a Group:
groupdel groupname
- Example:
sudo groupdel group0022
- Example:
Note:
- You cannot remove a group if it is the primary group of any existing user.
- Check all file systems to ensure that no files remain on the system that are owned by the group.
-
Change a User's Primary Group:
usermod -g groupname username
- Example:
id user02 sudo usermod -g group01 user02 id user02
- Example:
-
Add a User to a Supplementary Group:
usermod -aG groupname username
- Example:
id user03 sudo usermod -aG group01 user03 id user03
- Example:
Important:
- The
-a
option makesusermod
function in append mode. Without-a
, the user will be removed from any of their current supplementary groups that are not included in the-G
option's list.
group(5)
,groupadd(8)
,groupdel(8)
, andusermod(8)
man pages