liph:x:1000:1000:liph,,,:/home/liph:/bin/bash 1 2 3 4 5 6 7 1: login name 2: encrypted password, /etc/shadow 3: user id(uid), root is 0 4: group id(gid) 5: comment 6: home directory 7: login shell
/etc/shadow
1 2 3 4 5 6 7 8 9 10 11
liph:xxxxx:19171:0:99999:7::: 1 2 3 4 5 6789 1: login name 2: encrypted password 3: date of last password change, expressed as the number of days since Jan 1, 1970. 4: minimum password age 5: maximum password age 6: password warning period 7: password inactivity period 8: account expiration date 9: reserved field
/etc/group
1 2 3 4 5 6
liph:x:1000:abc,bcd 1 2 3 4 1: group name 2: encrypted password, /etc/gshadow 3: group id(gid), root is 0 4: user list, user name list(not uid), many login names can have the same uid
structpasswd { char *pw_name; /* username */ char *pw_passwd; /* user password */ uid_t pw_uid; /* user ID */ gid_t pw_gid; /* group ID */ char *pw_gecos; /* user information */ char *pw_dir; /* home directory */ char *pw_shell; /* shell program */ };
#include<grp.h>
struct group *getgrnam(constchar *name); struct group *getgrgid(gid_t gid);
structgroup { char *gr_name; /* group name */ char *gr_passwd; /* group password */ gid_t gr_gid; /* group ID */ char **gr_mem; /* NULL-terminated array of pointers to names of group members */ };