First look at the / etc / group file:
[[email protected] /]# cat /etc/group root:x:0:root bin:x:1:root,bin,daemon daemon:x:2:root,bin,daemon sys:x:3:root,bin,adm adm:x:4:root,adm,daemon tty:x:5: disk:x:6:root lp:x:7:daemon,lp mem:x:8: kmem:x:9: wheel:x:10:root ...
- ==User group name==
- ==User group password = =: this setting is usually used by the user group administrator.
- ==GID = =: user group ID
- ==Account name supported by this user group = =: an account can join multiple user groups. If a user wants to join a user group, just add the user name of the user to this field.
Initial user group
The fourth field (GID) in the line corresponding to the user in / etc / passwd is the initial user group. When a user logs in to the system, he or she immediately has the relevant permissions of the initial user group.
[[email protected] /]# cat /etc/passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt mail:x:8:12:mail:/var/spool/mail:/sbin/nologin ...
Valid user groups
A valid user group represents the user group that the user is in at this time. Before switching effective user groups, the effective user group is the initial user group.
To know the user’s current effective user group and supported user group (the fourth field in the / etc / group file contains the user’s user group), use the
[[email protected] /]# groups root bin daemon sys adm disk wheel
In the output information, the first output user group is the current effective user group (but some systems do not).
If I use
touchTo create a new file, the owner of the file is root, and the user group is root.
Switch valid user group: newgrp
newgrpThe command can switch effective user groups. Note that only the user groups supported by the current account can be switched.
Suppose the current user supports two user groups: “test” and “foo”. Then newgrp test and newgrp foo are valid. Everything else is invalid.
The principle behind this transformation is to create a new shell. If you want to recover to the previous user group, you need to use exit or Ctrl + D to log out the current shell.