All modern Linux operating systems use the /etc/shadow file to store user passwords in an encrypted hashed format. Only root users or commands with suid bit can access the /etc/shadow file. All other user information, such as user names, home directory, and default shell, is stored in the /etc/passwd file. Let us learn more about the passwords of the users located in the Linux operating system and related commands.
As stated earlier, the /etc/passwd is the password file that stores each user account without password. However, the passwords located in Linux /etc/shadow file. It stores the password hash information for the user account and optional password ageing information. Finally, the /etc/group file is a text file that defines the groups on the system. Each user has one entry per line in those two files.
Tutorial details | |
---|---|
Difficulty level | Easy |
Root privileges | Yes |
Requirements | Linux terminal |
Category | User Management |
OS compatibility | Alma • Alpine • Arch • CentOS • Debian • Fedora • Linux • Mint • openSUSE • Pop!_OS • RHEL • Rocky • Stream • SUSE • Ubuntu • WSL |
Est. reading time | 5 minutes |
The encrypted passwords and other information such as password expiry information (the password aging information) are stored in /etc/shadow file. All fields are separated by a colon (:) symbol. It contains one entry per line for each user listed in /etc/passwd file. Generally, shadow file entry looks as follows:
The order is as follows:
A password hash is nothing but a string that verifies the integrity of your password during login against the stored hash so that your actual password never has to be held in /etc/shadow file. It is a security feature.
The normal user cannot access the /etc/shadow file directly. For example, try out the following cat command or more/less/bat command as follows:$ cat /etc/shadow
Here is what you will see:
cat: /etc/shadow: Permission denied
You can only access the /etc/shadow file via few commands such as the passwd command. Login as root user and execute cat command on /etc/shadow file:$ su -
Provide root user password when prompted:
Password:
Now, try to display the file:# cat /etc/shadow
Sample outputs:
root: $1$s83Ugoff$EDT83WAAFpCQHWDp07E9Ux:0:99999:7::: daemon:*:13031:0:99999:7::: bin:*:13031:0:99999:7::: .... ......
Here is how my encrypted password hash looks on Linux:
vivek:$6$LONG_STRING_HASH_HERE1:18770:0:99999:7:::
We can use the chage command to get account aging information in easy to understand format:$ chage -l vivek
And now I see:
Last password change : May 23, 2021 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
Each each entry in the /etc/shadow (or outputs from the chage command) is divided into following fields:
Of course, you can use the sudo command as follows. For example, if you are a Linux system administrator or part of an admin group, then:$ sudo cat /etc/shadow
Or grep command along with the sudo:$ sudo cat /etc/shadow | grep vivek
OR avoid useless use of the cat command:$ sudo grep vivek /etc/shadow
Please note that FreeBSD uses /etc/master.shadow file.
To get entries from Name Service Switch libraries use the getent command. The syntax is:$ getent database key
$ getent [option] database key
Where database can be:
Try these examples:$ getent passwd
$ getent passwd vivek
$ getent group
$ getent group vivek
$ sudo getent shadow
$ sudo getent shadow vivek
Now you know where are the passwords of the users located in Linux. I suggest that you read the following man pages using the man command or help command (you can read them online on Debian or Ubuntu manual page section too):$ man getent
$ man 5 shadow
$ man 5 passwd
Yerusalem - Iran mengonfirmasi telah meluncurkan puluhan pesawat nirawak (drone) dan rudal ke arah Israel…
New York - Utusan tetap Iran untuk Perserikatan Bangsa-bangsa (PBB) mengatakan bahwa tindakan militer Republik…
Teheran - Juru bicara pasukan militer Israel Daniel Hagari pada Minggu mengatakan Iran telah meluncurkan…
Kemunculan iklan di HP Android termasuk Xiaomi bukanlah hal baru bagi pengguna. Iklan-iklan tersebut biasanya…
Cara menghilangkan iklan di HP Xiaomi dibutuhkan ketika pengguna mulai terganggu dengan adanya iklan-iklan yang bermunculan di layar…
Serang - Ramadan adalah bulan yang istimewa bagi umat Islam di seluruh dunia. Di bulan suci ini…