Understanding the /etc/passwd
File
In this step, we will explore the structure and meaning of the /etc/passwd
file.
On Linux systems, user password information is stored in two files: /etc/passwd
and /etc/shadow
. The /etc/passwd
file contains user information, with each line representing a single user account. Each line is divided into seven colon-separated fields:
- Username
- Password (if set to
x
, the password is stored in /etc/shadow
)
- User ID (UID, 0 for the root user)
- Group ID (GID)
- User Information (Full Name, Room Number, Work Phone, Home Phone, and Other)
- Home directory
- Default shell
Now, Open a terminal and Navigate to the /home/labex/project
directory to proceed to the next step.
cd /home/labex/project
Get labex
user's information from the /etc/passwd
file and save it to a file named labex_passwd.txt
in the /home/labex/project
directory.
grep labex /etc/passwd > /home/labex/project/labex_passwd.txt
Check the contents of the labex_passwd.txt
file.
cat labex_passwd.txt
Expected output:
labex:x:5000:5000::/home/labex:/usr/bin/zsh
Here's what each field represents:
- Username: test-user
- Password: stored in
/etc/shadow
(indicated by x
)
- UID: 5000
- GID: 5000
- User Information: In this case, it's empty
- Home directory:
/home/labex
- Default shell:
/usr/bin/zsh
During the Linux authentication process, the following steps occur:
- The entered username is checked against the first field in each line of the
/etc/passwd
file.
- If a match is found, the password in the second field is compared.
- Upon successful authentication, the user's permissions are determined by the UID (third field) and GID (fourth field).
- Importantly, a UID of
0
represents the root user, granting full administrative privileges, regardless of the username.
As you can see, the /etc/passwd
file plays a critical role in the Linux authentication process. If an attacker can modify this file, they may be able to gain unauthorized access and escalate their privileges.