0
0
Linux CLIscripting~20 mins

/etc/passwd and /etc/shadow in Linux CLI - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Shadow and Passwd Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
What is the output of this command?
You run the command cut -d: -f1 /etc/passwd | head -3. What is the expected output?
Linux CLI
cut -d: -f1 /etc/passwd | head -3
A
root
sys
adm
B
root
bin
daemon
C
root
daemon
bin
D
daemon
bin
sys
Attempts:
2 left
💡 Hint
The first field in /etc/passwd is the username. The command extracts usernames and shows the first three.
🧠 Conceptual
intermediate
1:30remaining
What is the main difference between /etc/passwd and /etc/shadow?
Choose the correct statement about the difference between /etc/passwd and /etc/shadow files.
A/etc/passwd is readable by all users, /etc/shadow is readable only by root and stores encrypted passwords.
B/etc/passwd stores encrypted passwords, /etc/shadow stores user IDs.
C/etc/shadow stores usernames, /etc/passwd stores passwords in plain text.
D/etc/passwd and /etc/shadow both store passwords in plain text.
Attempts:
2 left
💡 Hint
Think about file permissions and security of password storage.
🔧 Debug
advanced
1:30remaining
Why does this script fail to read /etc/shadow?
A user runs this script to read the first line of /etc/shadow:
#!/bin/bash
head -1 /etc/shadow
But it shows a permission denied error. Why?
A/etc/shadow is only readable by root, normal users cannot read it.
Bhead command does not work on /etc/shadow file.
CThe script is missing execute permission.
DThe script syntax is incorrect.
Attempts:
2 left
💡 Hint
Check file permissions of /etc/shadow.
🚀 Application
advanced
2:00remaining
Extract usernames with locked passwords from /etc/shadow
Which command correctly lists usernames whose password field in /etc/shadow starts with an exclamation mark (!) indicating locked accounts?
Ased -n '/^!/p' /etc/shadow
Bawk -F: '$2 ~ /^!/ {print $1}' /etc/shadow
Ccut -d: -f1 /etc/shadow | grep '!'
Dgrep '^!' /etc/shadow | cut -d: -f1
Attempts:
2 left
💡 Hint
Look for lines where the second field starts with ! and print the first field.
📝 Syntax
expert
1:30remaining
What error does this command produce?
What error will this command produce?
cut -d: -f1 /etc/shadow | head -3
ANo output, command runs silently
BFile not found error
CSyntax error due to wrong delimiter
DPermission denied error because /etc/shadow is restricted
Attempts:
2 left
💡 Hint
Consider file permissions of /etc/shadow for normal users.