Bird
0
0

You want to automate changing passwords for multiple users listed in a file users.txt. Which script snippet correctly changes each user's password to NewPass123 using passwd?

hard📝 Application Q15 of 15
Linux CLI - Users and Groups
You want to automate changing passwords for multiple users listed in a file users.txt. Which script snippet correctly changes each user's password to NewPass123 using passwd?
Afor user in $(cat users.txt); do echo -e "NewPass123\nNewPass123" | passwd $user; done
Bwhile read user; do echo "NewPass123" | passwd --stdin $user; done < users.txt
Cfor user in users.txt; do passwd $user NewPass123; done
Dcat users.txt | passwd -p NewPass123
Step-by-Step Solution
Solution:
  1. Step 1: Understand how to feed password to passwd

    The passwd command reads password from standard input when piped, requiring password twice (new and confirmation).
  2. Step 2: Analyze each script snippet

    while read user; do echo "NewPass123" | passwd --stdin $user; done < users.txt uses --stdin which is not standard on all systems. for user in $(cat users.txt); do echo -e "NewPass123\nNewPass123" | passwd $user; done correctly uses echo -e to send password twice piped to passwd. for user in users.txt; do passwd $user NewPass123; done incorrectly treats file name as user list. cat users.txt | passwd -p NewPass123 misuses passwd with pipe and -p which is invalid.
  3. Final Answer:

    for user in $(cat users.txt); do echo -e "NewPass123\nNewPass123" | passwd $user; done -> Option A
  4. Quick Check:

    Pipe password twice to passwd in loop = B [OK]
Quick Trick: Pipe password twice with echo -e inside loop to automate [OK]
Common Mistakes:
  • Using non-standard --stdin option
  • Not sending password twice for confirmation
  • Treating filename as username list without reading
  • Misusing passwd options

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes