What is the purpose of the /etc/passwd file in Linux?
The /etc/passwd file stores basic information about user accounts, such as username, user ID, group ID, home directory, and default shell. It is readable by all users.
Click to reveal answer
beginner
Why is the /etc/shadow file separated from /etc/passwd?
The /etc/shadow file stores encrypted user passwords and related security information. It is kept separate and readable only by the root user to protect password security.
Click to reveal answer
intermediate
What kind of information does each line in /etc/passwd contain?
Each line has 7 fields separated by colons: username, password placeholder (usually 'x'), user ID (UID), group ID (GID), user info (comment), home directory, and default shell.
Click to reveal answer
intermediate
Who can read the /etc/shadow file and why?
Only the root user or processes with root privileges can read /etc/shadow because it contains sensitive encrypted password data that must be protected from unauthorized access.
Click to reveal answer
intermediate
How does Linux use /etc/passwd and /etc/shadow together during login?
Linux uses /etc/passwd to find user details and /etc/shadow to verify the encrypted password during login. This separation improves security by limiting password exposure.
Click to reveal answer
Which file contains the encrypted passwords in a Linux system?
A/etc/shadow
B/etc/passwd
C/etc/group
D/etc/login
✗ Incorrect
Encrypted passwords are stored in /etc/shadow to keep them secure and restrict access.
What does the 'x' in the password field of /etc/passwd indicate?
AUser has no password
BPassword is stored in /etc/shadow
CUser account is locked
DPassword is empty
✗ Incorrect
The 'x' means the actual password is stored securely in /etc/shadow.
Who can read the /etc/passwd file by default?
ANo one
BOnly users in the admin group
COnly root user
DAll users
✗ Incorrect
/etc/passwd is world-readable because it contains non-sensitive user info.
What is the main reason for separating password data into /etc/shadow?
ATo protect password security by restricting access
BTo speed up login
CTo allow users to edit their passwords
DTo store user groups
✗ Incorrect
Separating passwords into /etc/shadow restricts access to sensitive data.
Which field in /etc/passwd specifies the user's default shell?
AFirst field
BThird field
CSeventh field
DSixth field
✗ Incorrect
The seventh field in /etc/passwd is the user's default shell.
Explain the roles of /etc/passwd and /etc/shadow files in Linux user management.
Think about what info is public and what needs protection.
You got /4 concepts.
Describe the typical fields found in a line of /etc/passwd and their meanings.
There are seven fields separated by colons.
You got /7 concepts.
Practice
(1/5)
1. What is the primary purpose of the /etc/passwd file in Linux?
easy
A. To store encrypted user passwords securely
B. To configure network settings
C. To store user account information accessible to all users
D. To log system errors
Solution
Step 1: Understand the role of /etc/passwd
The /etc/passwd file contains user account details like username, user ID, group ID, home directory, and shell. It is readable by all users.
Step 2: Differentiate from /etc/shadow
The encrypted passwords are stored separately in /etc/shadow for security, not in /etc/passwd.
Final Answer:
To store user account information accessible to all users -> Option C
Quick Check:
/etc/passwd = user info file [OK]
Hint: Remember: passwd = public user info, shadow = private passwords [OK]
Common Mistakes:
Confusing /etc/passwd with /etc/shadow
Thinking passwords are stored in /etc/passwd
Assuming /etc/passwd stores system logs
2. Which of the following lines correctly shows the format of a typical /etc/shadow entry?
easy
A. username:x:1000:1000:User Name:/home/user:/bin/bash
B. username:$6$randomsalt$encryptedpassword:18000:0:99999:7:::
C. username:password:1000:1000:User Name:/home/user:/bin/bash
D. username:encryptedpassword:1000:1000:User Name:/home/user:/bin/bash
Solution
Step 1: Identify /etc/shadow format
The /etc/shadow file stores encrypted passwords and related info. The password field looks like $6$randomsalt$encryptedpassword for SHA-512 encryption.
Step 2: Compare options
The line username:$6$randomsalt$encryptedpassword:18000:0:99999:7::: matches the shadow file format with encrypted password (indicated by $6$) and password aging fields separated by colons. The other options resemble /etc/passwd format or have incorrect password fields.
Final Answer:
username:$6$randomsalt$encryptedpassword:18000:0:99999:7::: -> Option B
Quick Check:
/etc/shadow entries have encrypted passwords with $ signs [OK]
Hint: Look for $ signs and many colon-separated fields in shadow entries [OK]
Common Mistakes:
Confusing /etc/passwd format with /etc/shadow
Expecting plain text passwords in /etc/shadow
Missing fields after encrypted password
3. Given the following command:
grep '^root:' /etc/passwd | cut -d':' -f1,3,7
What will be the output format?
medium
A. root:/bin/bash
B. root:x:0:0:root:/root:/bin/bash
C. root:0:0
D. root:0:/bin/bash
Solution
Step 1: Understand the command parts
grep '^root:' /etc/passwd finds the line starting with 'root:'. cut -d':' -f1,3,7 extracts fields 1 (username), 3 (UID), and 7 (shell) separated by colons.
4. You run this command to check password expiry info:
sudo chage -l username
But it shows an error: chage: user 'username' does not exist. What is the most likely cause?
medium
A. The username is missing in /etc/passwd
B. The /etc/shadow file is empty
C. The chage command is not installed
D. The user has no password set
Solution
Step 1: Understand chage user check
The chage command checks user password expiry info by looking up the username in /etc/passwd.
Step 2: Analyze error cause
Error 'user does not exist' means the username is not found in /etc/passwd. If the user was missing there, chage cannot proceed.
Final Answer:
The username is missing in /etc/passwd -> Option A
Quick Check:
User must exist in /etc/passwd for chage to work [OK]
Hint: Check /etc/passwd for username before using chage [OK]
Common Mistakes:
Assuming /etc/shadow emptiness causes this error
Thinking chage command missing causes user error
Believing no password set triggers 'user does not exist'
5. You want to write a script that lists all users who have a valid login shell (not /usr/sbin/nologin or /bin/false) by reading /etc/passwd. Which command snippet correctly filters these users?