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)