45. Group Management - Creation, Modification and Deletion
Contents
To make it easier to manage groups, linux provides some common commands that allow you to add, delete, and modify groups in a more standardized way.
Add Group
We can add groups through the groupadd command.
Here are some common options for groupadd command:
Option | Meaning |
---|---|
-g or ‑‑gid | Specify the group’s ID. The specified value must be greater than or equal to the value of the GID_MIN variable in the /etc/login.defs configuration file and less than or equal to the value of the GID_MAX variable in the same file. |
-r or ‑‑system | If this option is specified, the created group is a system group. The system group’s id range is between the values of the SYS_GID_MIN and SYS_GID_MAX variables in the /etc/login.defs configuration file. |
Add Groups
Let’s add new groups:
|
|

Output the three newly created groups
Modify Group
We can modify the group information through the groupmod command.
Here are some common options for groupmod command:
Option | Meaning |
---|---|
-g or ‑‑gid | Specify the group’s new ID. |
-n or ‑‑new-name | Specify the group’s new name. |
Modify Group Name
Let’s modify the group’s name:
|
|

Output the last group before and after its name modification
Delete Group
Let’s delete the group:
|
|

Output the last group before and after its deletion
Group Password
We can use the gpasswd command to specify or change the login password for the group.
Here are some common options for gpasswd command:
Option | Meaning |
---|---|
-a or ‑‑add | Add the user to group. |
-d or ‑‑delete | Delete the user from group. |
-r or ‑‑remove-password | Remove the password from the group. |
Create Password for Groups
|
|

Output the gshadow file before and after the newly created group's password modification
New Group
With the newgrp command, we can have the user log in to another group.
Log in to Another Group
Log in and log out of another group:
|
|

Output the user's id and group ids before and after the user's entry and exit of the another group
References GROUPADD(8), GROUPMOD(8), GROUPDEL(8), GPASSWD(1), NEWGRP(1)
Author Dong Chen
LastMod Sun Mar 17 2019