Understand the /etc/shadow File
In this step, you will learn about the structure and purpose of the /etc/shadow
file.
The /etc/shadow
file stores encrypted passwords and password-related configuration information for each user account. Each line in the file represents one user and contains 9 colon-separated fields:
- Username
- Encrypted password hash
- The number of days since the epoch (1970-01-01) that the password was last changed
- The minimum number of days required between password changes
- The maximum number of days the password is valid
- The number of days before password expiration to warn the user
- The number of days after password expiration before the account is disabled
- The number of days since the epoch (1970-01-01) that the account will be disabled
- A reserved field for future use
Open a terminal and navigate to the /home/labex/project
directory.
cd /home/labex/project
Let's check the labex
user's entry in the /etc/shadow
file:
sudo cat /etc/shadow | grep labex > /home/labex/project/labex_shadow.txt
Notice that we used sudo
to read the /etc/shadow
file. This is because the file is only readable by the root user.
Check the contents of the labex_shadow.txt
file:
cat labex_shadow.txt
Example output:
labex:$y$j9T$enO.7A1WiUBiOvRdw4gox0$cCOqZqHAQgLkhPb.NDJO9zO6T3EUQ3.AeE0amN57AZ8:19818:0:99999:7:::
This line indicates:
- Username:
labex
- Encrypted password hash:
$y$j9T$enO.7A1WiUBiOvRdw4gox0$cCOqZqHAQgLkhPb.NDJO9zO6T3EUQ3.AeE0amN57AZ8
- Last password change: 19818 days since the epoch (1970-01-01)
- Minimum password age: 0 days (no restriction)
- Maximum password age: 99999 days (no expiration)
- Password warning period: 7 days before expiration
- Account never expires
By default, only the root user can read and modify the /etc/shadow
file. However, misconfigured
permissions can sometimes provide opportunities for privilege escalation.