Linux uses commands to add the same user to multiple groups

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.