Linux users and password file format detailed

This article introduces the format of the two files /etc/passwd and /etc/shadow under the Linux system. Of these two files, one is the storage of user account information data, and the other is the storage of user password information and password expiration related information. Both of these files use colons as separators to separate fields. For safety, only the super administrator can read and write these two files.

1. The format of the /etc/passwd file, using 7 segments of user account information separated by colons

account:password:UID:GID:GECOS:directory:shell ( Account: Password: User ID: Group ID: General Information: Directory: Shell)

Example: root:x:0:0:root:/root:/bin/bash

  1. Account name
  2. Password placeholder, replace with x
  3. User ID
  4. Basic Group ID
  5. GECOS, yes Understand as the user’s full name
  6. user’s home directory
  7. user shell

2. /etc/shadow file format, 9 segments separated by colons Password related information

liuqing:$6$HE1uq5GI$1BUG8ACoUscfpvuW:18192:0:99999:7:::

1.login name Login name: must be a valid account name, and Already exist in the system.

  1. date of last password change encrypted password: encrypted password, this password is a password with the random number salt added. Separate with $. In this way, users who use the same password will not get the same encrypted value. When verifying the password, the password entered by the user is combined with the salt (existing in the corresponding user line of the shaodw file) to verify the consistency with the encrypted password.
  2. date of last password change: The date of the last password change. This date is calculated from January 1, 1970. 0 means that the user should change the password the next time they log in, and an empty field means that the password aging function is disabled.
  3. date of last password change Minimum password expiration date: After the user has changed the password once, how many days will it take to change the password again? An empty field or 0 means that there is no minimum password lifetime.
  4. maximum password age Maximum password age: the maximum number of days after the user’s password has been used, it must be changed. After this point in time, the password is still valid, but you need to change the password the next time you log in. If this field is empty, it means that there is no longest password expiration period, no password warning time period, and no password disable time period. If the maximum password period is less than the minimum password period, the user cannot change the password.
  5. password warning period: The number of days to warn the user in advance before the password expires. An empty field or 0 means there is no password warning period.
    7.password inactivity period Password inactivity period: the number of days after the password has expired (the maximum use period of the password), the password is still accepted (during this period, the user should change the password at the next login). After the password expires and the grace period has passed, you will not be able to log in with the current password. An empty field means that the password is not forced to expire.
  6. account expiration date: The account expiration date, which means the number of days since January 1, 1970. Note that account expiration is different from password expiration. When the account expires, the user will not be allowed to log in; when the password expires, the user will not be allowed to log in with their password. An empty field means that the account will never expire.
  7. Reserved field: This field is reserved for future use.

Leave a Comment

Your email address will not be published.