Add a user to multiple groups in Linux

Source: Internet
Author: User

Original address http://hi.baidu.com/windox/blog/item/01757ccb0468901fbe09e68a.html

Add a user to multiple groups in Linux
The implementation method is as follows:
Gpasswd-a user group
If you are viewing files such as/etc/shadow or/etc/passwd, you cannot see that this user has joined the desired group,
You should use the ID to view

EP:
The user Ruan belongs to the Ruan group with the ID of 500. Now you want to join the group ruanrongjian at the same time.

[Root @ diandianrong ~] # Gpasswd-A Rong ruanrongjian
Adding User Rong to group ruanrongjian
Switch to the Ruan user first, and then use the ID to view
[Root @ diandianrong ~] # Su Ruan
[Ruan @ diandianrong root] $ ID
Uid = 500 (Ruan) gid = 500 (Ruan) groups = 500 (Ruan), 501 (ruanrongjian) Context = user_u: system_r: unconfined_t
Of course, you can use ID Ruan directly.

[Ruan @ diandianrong root] $ id Ruan
Uid = 500 (Ruan) gid = 500 (Ruan) groups = 500 (Ruan), 501 (ruanrongjian)
In this case, two groups are added. The Group Ruan is generated automatically when the user is created, and the ruanrongjian is manually added later.

Another implementation method:

[Root @ diandianrong ~] # Usermod-G Rong ruanrongjian
[Root @ diandianrong ~] # ID Rong
Uid = 502 (Rong) gid = 502 (Rong) groups = 502 (Rong), 501 (ruanrongjian)
 

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.