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
Adding a group: Groupadd Group name
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 //See what Likui belongs to Group Sorry:sorry[[email protected] sorry]# gpasswd-a sorry Bob //Add Likui to 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------. Orry Sorry 4096 June 20:14 likuidrwx------. 3 Tom Tom June 20:27 Tom[[email protected] sorry]# groupadd Bob //Create a Bob Group [email protected] sorry]# gpasswd-a Sorry Bob //Give Bob's permission to sorry user [[email protected] sorry]# gpasswd-a Tom BOB //Under sorry user, Add Tom to the Bob Group adding user Tom to group BOB //display added [Root[email protected] sorry]# groups Tom //See which groups Tom users belong to C15>tom:tom Bob[[email protected] sorry]# gpasswd-d Tom Bob //Under Sorry users, remove Tom from the BOB group removing user Tom from Group 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);
Active Group switching: 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