Linux accounts and user groups
1. users and groups
When logging on to linux, you must enter your account. Linux only recognizes the User ID and User ID, referred to as the User Group that the UID belongs to, Group ID, or GID.
2. User Account
The user account is related to two files in linux:/etc/passwd and/etc/shadow./etc/passwd to save the user account information. /Etc/shadow is used to manage password-related data.
/Etc/passwd file
$ head -4 /etc/passwdroot:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologinadm:x:3:4:adm:/var/adm:/sbin/nologin
Each line represents an account. Some accounts are required for system operation, such as bin, daemon, adm, and nobody.
Separated by:. There are 7 fields in total: 1: Account name 2: Password Saved earlier, password data is now saved in/etc/shadow, so it is now replaced by x. 3: UID 0: System Administrator; 1-499: system account; 500-65535: normal user account. 4: GID group ID 5: User Information Description column 6: After a user logs on to the main folder, the user will be in the user's home directory. The default user home directory is/home/yourID name 7: shell obtained after logon.
/Etc/shadown File
$ head -4 /etc/shadowroot:$1$l0aFE9hs$d1/FIMqIl3foYUl3ETyk10:16353:0:99999:7:::bin:*:13361:0:99999:7:::daemon:*:13361:0:99999:7:::adm:*:13361:0:99999:7:::
View permissions, generally set to root read-only
ll /etc/shadow-r-------- 1 root root 1085 Nov 21 03:40 /etc/shadow
Separated by:. A total of 9 fields 1: Account name 2: encrypted password field. 3: The last password change date is the number of accumulated days from January 1. 4: the number of days for which the password cannot be changed. 0 indicates no limit. 5: the number of days for the password to be changed. 99999 is calculated as 273. 6: the number of days for which the password needs to be changed. 7: after the password expires, you can log on to the account at the same time. After logon, force the password to be changed. 8: Account expiration date. The account cannot be used. 9: reserved field.
3. User Group
User group data is stored in the/etc/group file.
$ head -4 grouproot:x:0:rootbin:x:1:root,bin,daemondaemon:x:2:root,bin,daemonsys:x:3:root,bin,adm
A row represents a user group. The files are separated by:. There are 4 columns in total.
1: User Group name 2: user group password usually does not need to be set. The password file is/etc/gshadow 3: GID 4: users supported by the user group.
Initial user group initial group: GID in/etc/passwd is the user's initial user group valid user group. A user can have multiple groups, and the current group is a valid user group.
$ groupsroot bin daemon
Use the groups command to view the user group. The first user group that appears is a valid user group.
You can use newgrp groupname to switch between groups.
/Etc/gshadow group Password File
head -4 /etc/gshadow root:::rootbin:::root,bin,daemondaemon:::root,bin,daemonsys:::root,bin,adm
Use: Separate, four columns 1: group name 2: Password 3: User Group Administrator Account 4: User Account of the user group.