1. Viewing the user's effective group
Groups user Name
Note: There may be multiple results from the view; The first is the primary group, followed by the sub-group
2. Adding and removing groups
To Add a group: groupadd Group name
To Delete a group: Groupdel Group name
to add a user to a group: gpasswd -a user 1
Create a Bob Group Groupadd Bob
Add User 1 to the Bob Group gpasswd-a user 1 Bob
parameters: -A add
-D Delete
-a set a user as the administrator of the group
For example1:(add user to a group)
[[email protected] sorry]# groupadd BOB //Create a group [[email protected] sorry]# groups sorry //view Likui belongs to which group -a sorry Bob //Add Likui to the BOB group
For example2: ( set a user as the administrator of a group )
[Email protected] sorry]# Useradd Tom//Create a Tom user[Email protected] sorry]# ll/home/ Total4drwx------. -Sorry sorry4096June A -: -likuidrwx------.3Tom Tom +June A -: -Tom[[email protected] sorry]# groupadd BOB//Create a Bob group[Email protected] sorry]# gpasswd-a Sorry BOB//give Bob's permission to sorry users[Email protected] sorry]# gpasswd-a Tom BOB//under the sorry user, add Tom to the Bob GroupAdding user Tom to group BOB//the display is added in[email protected] sorry]# groups Tom//See which groups Tom users belong totom:tom bob[[email protected] sorry]# gpasswd-D Tom BOB//Delete Tom from the Bob Group under the sorry userremoving user Tom fromgroup Bob[[email protected] sorry]#
3, effective group of switching
Newgrp
If a user's effective group has multiple: Group 1; Group 2 ..... (The default group 1 is the main group, the other group is the sub-group);
switching of effective groups : newgrp Group 2 user name
after switching, the user's valid group is: Group 2: Group 1 ...
Linux Account Management Chapter II: Management of user groups