When the Linux system adds users to groups (group), use the gpasswd-a or USERMOD-AG commands.
Several ways to add users to a group
When creating a user, there are several ways to add users to a specified group.
The code is as follows |
Copy Code |
(1) Specify group when creating user # useradd-g [group name or GID]-G [additional group or GID] [user name] (2) Use the Usermod command to specify the group # usermod-g [group name or GID]-G [additional group or GID] [user name] (3) The Usermod command uses the-AG option to specify the added group # Usermod-ag [group name] [user name] (4) GPASSWD command to add the specified user to the specified group # gpasswd-a [user name] [group name] Note When using the Usermod command |
When you use the Usermod command to specify a group with the-G option only, note that the user will exit from all of the original groups and only those specified with the-G option.
code is as follows |
copy code |
# Mans Usermod -A,--append Add the user to the supplementary group (s). Use only with THE-G option. -G,--groups group1[,group2,... [, GROUPN]]] A list of supplementary groups which the user is also a. Each group are separated from the next by a comma with no intervening whitespace. The groups are subject to the same restrictions as the group given with THE-G option. If the user is currently a member of a group which isn't listed, the user would be removed from the group. This behaviour can is changed via the-a option, which appends the user to the current supplementary group list. |
Actual operation
The following is an example of a Zabbix user who executes the results of gpasswd-a, usermod-g, and Usermod-ag commands.
code is as follows |
copy code |