Using the Usermod command in the RHEL7.2 system to add a user to multiple additional groups, by default, adding multiple additional groups at once can be added in the following ways:
Usermod-g Additional Group 1, additional Group 2, ..., additional group N user name
Instance
[Email protected] ~]# Useradd MK
[[email protected] ~]# ID MK
uid=1159 (MK) gid=1159 (MK) group =1159 (MK)
[Email protected] ~]# Groupadd Mk1
[Email protected] ~]# Groupadd Mk2
[Email protected] ~]# Groupadd Mk3
[Email protected] ~]# Usermod-g Mk1,mk2,mk3 mk
[[email protected] ~]# ID MK
uid=1159 (MK) gid=1159 (MK) group =1159 (MK), 1161 (MK1), 1162 (Mk2), 1163 (MK3)
However, if you add additional groups to the user after adding them, use the
Usermod-g additional group name User name
Will overwrite the user's previous additional group. At this point, you can add a parameter- A to the Usermod command.
Usermod-a-G Additional Group name user name
Instance
[[email protected] ~]# ID Top
uid=1034 (top) gid=1034 (top) group =1034 (top), (Don)
[Email protected] ~]# Usermod-g MK Top
[[email protected] ~]# ID Top
uid=1034 (top) gid=1034 (top) group =1034 (top), 1159 (MK)
[Email protected] ~]# usermod-a-G Don Top
[[email protected] ~]# ID Top
uid=1034 (top) gid=1034 (top) group =1034 (top), (Don), 1159 (MK)
This article is from a "non-secure" blog, so be sure to keep this source http://renzhe27.blog.51cto.com/1735477/1763734
Linux uses commands to add the same user to multiple groups