Understanding Linux /etc/shadow File Format

The /etc/shadow file stores actual password in encrypted format and other passwords related information such as user name, last password change date, password expiration values, etc,.

It’s a text file and readable only by the root user and is therefore less of a security risk.

The /etc/shadow file contain every user details as a single line with nine fields, each fields separated by colon :.

We had already written an article about Linux /etc/passwd file format in previous post. As earlier explained in the /etc/passwd file that second field written as (x), which means shadowing is enabled and encrypted password exists for that user in another file “/etc/shadow”.

The encrypted passwords can be stored in /etc/passwd file and the same was followed in the initial days. But it’s not recommended due to world readable permissions on the /etc/passwd file.

Also, /etc/passwd doesn’t allow to store other password related information since the /etc/passwd file has only one field for password information.

To mitigate all these issue, they had created the /etc/shadow file and allowed to store encrypted password and other password related information.

The /etc/login.defs file provides default configuration information for user account password parameters. It defines, Password ageing related information such as password Min/Max days, password warning age, etc.,

# grep PASS /etc/login.defs

#	PASS_MAX_DAYS	Maximum number of days a password may be used.
#	PASS_MIN_DAYS	Minimum number of days allowed between password changes.
#	PASS_WARN_AGE	Number of days warning given before a password expires.

How to Access /etc/shadow File in Linux?

As i told in the beginning of the article, it’s a text file and readable only by the root user. Use any file manipulation commands to access it.

I have trimmed the file for better understanding.

# cat /etc/shadow

What are the Nine Fields and it’s Details?

The /etc/shadow file contain every user password details as a single line with nine fields as described below, each fields separated by colon :.

The password field comes with following three variants.

  • Usable Encrypted Password: This allow us to login to the Linux system since it’s comes with proper password.
  • Locked Password: A password field which starts with a exclamation mark means that the password is locked.
  • (! and *) Represent Empty Password: This field may be empty, in which case no passwords are required to authenticate as the specified login name. These user will not be able to use a unix password to log in.

These are the Nine fields, which is in /etc/shadow file.

  • Username: User login name, it be a valid account name, which exist on the system.
  • Encrypted Password: Encrypted Password hash, which contains three parts like hash_algorithm, hash_salt, and hash_data.
  • Date of last password change: The date of the last password change, expressed as the number of days since Jan 1, 1970.
  • Minimum password age: The minimum password age is the number of days the user will have to wait before she will be allowed to change her password again.
  • Maximum password age: The maximum password age is the number of days after which the user will have to change her password.
  • Password warning period: The number of days before a password is going to expire (see the maximum password age above) during which the user should be warned.
  • Password inactivity period: The number of days after a password has expired during which the password should still be accepted. After expiration of the password and this expiration period is elapsed, no login is possible using the current user’s password.
  • Account expiration date: The date of expiration of the account, expressed as the number of days since Jan 1, 1970.
  • Reserved field: Not used or reserved for future use.
# grep "mageshm" /etc/shadow

mageshm:$6$sTgBhfj0$pkzz/JpVTl8ZAmk./d4SDarRyWsGSZHguljywUHQMP4DWo8/TgNzL5rMpejqNWuyxtFlISxdyIqPmpsIsyi.i1:16088:0:99999:7: : :
   1                                                       2                                                 3   4   5   6 7 8 9

Understanding the Password Hash Field and it’s Details?

The Password hash field contains an encrypted password instead of original password and the original password haven’t stored anywhere in system.
The encrypted password is having three fields and the field is separated by $ symbol.

These are the three fields, which is in password field.

  • hash_algorithm: This field shows which hashing algorithm used.
  • hash_salt: This field is contain encrypted password instead of actual password.
  • hash_data: This field is salted hash password.
 - -------- --------------------------------------------------------------------------------------
 1    2                                             3

Details of hash_algorithm

Details of hash_algorithm and it’s code.

| Code |        Algorithm       |
|  $1  | MD5 hashing algorithm  |
|  $2  | Blowfish Algorithm     |
|  $3  | Eksblowfish Algorithm  |
|  $4  | NT hashing algorithm   |
|  $5  | SHA-256 Algorithm      |
|  $6  | SHA-512 Algorithm      |

How to Check /etc/shadow File Permission?

Simply use ls command to check the /etc/shadow file permission.

# ls -la /etc/shadow
-rw------- 1 root root 942 Jun  1 22:14 /etc/shadow

How to View Users Password Properties in Linux?

Use chage command to check users password properties.

# chage -l daygeek
Last password change					: Feb 25, 2019
Password expires					: never
Password inactive					: never
Account expires						: never
Minimum number of days between password change		: 0
Maximum number of days between password change		: 99999
Number of days of warning before password expires	: 7

About Magesh Maruthamuthu

Love to play with all Linux distribution

View all posts by Magesh Maruthamuthu

One Comment on “Understanding Linux /etc/shadow File Format”

Leave a Reply

Your email address will not be published. Required fields are marked *