Bird
Raised Fist0
Linux CLIscripting~10 mins

passwd (change password) in Linux CLI - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - passwd (change password)
User runs 'passwd'
↓
Prompt: Enter current password
↓
User inputs current password
↓
Prompt: Enter new password
↓
User inputs new password
↓
Prompt: Confirm new password
↓
User confirms new password
↓
System checks passwords match
↓
Password [Error: Passwords do not match
↓
Restart new password prompt
↓
Success message
↓
Exit
The passwd command asks for the current password, then the new password twice, checks if they match, and changes the password if all is correct.
Execution Sample
Linux CLI
passwd
Enter current password:
Enter new password:
Retype new password:
This sequence shows the prompts when changing a password using the passwd command.
Execution Table
StepActionUser InputSystem CheckResult/Output
1Run 'passwd' commandPrompt: Enter current password:
2User enters current passwordcurrent_passwordVerify current passwordIf correct, prompt: Enter new password:
3User enters new passwordnew_passwordPrompt: Retype new password:
4User retypes new passwordnew_passwordCheck if new passwords matchIf match, password changed successfully
5If passwords do not matchmismatched_passwordCheck if new passwords matchError: Passwords do not match, prompt again for new password
6Password changedSuccess message: password updated
7ExitReturn to shell prompt
💡 Execution stops after successful password change or user aborts.
Variable Tracker
VariableStartAfter Step 2After Step 3After Step 4Final
current_passwordunsetuser inputuser inputuser inputused for verification
new_passwordunsetunsetuser inputuser inputused for confirmation and update
password_matchunsetunsetunsettrue/falsetrue if passwords match, else false
Key Moments - 3 Insights
Why does passwd ask for the new password twice?
To make sure the new password is typed correctly both times. If they don't match (see execution_table step 5), it asks again to avoid mistakes.
What happens if the current password is entered incorrectly?
The system will reject it and not proceed to new password prompts. This is shown in execution_table step 2 where verification fails and passwd exits or retries.
Can you see the password as you type it?
No, for security reasons the input is hidden (no characters shown). This prevents others from seeing your password.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what happens at step 4 if the new passwords match?
APassword is changed successfully
BError message is shown
CUser is asked to enter current password again
DThe command exits without changes
💡 Hint
Check the 'Result/Output' column at step 4 in the execution_table
At which step does the system verify the current password?
AStep 1
BStep 2
CStep 3
DStep 4
💡 Hint
Look at the 'System Check' column in the execution_table
If the new passwords do not match, what does the system do next?
AChanges the password anyway
BExits the command immediately
CShows an error and asks to re-enter new password
DAsks for current password again
💡 Hint
See the row for step 5 in the execution_table under 'Result/Output'
Concept Snapshot
passwd command changes user password
1. Enter current password for verification
2. Enter new password twice to confirm
3. If new passwords match, password updates
4. If mismatch, prompts again
5. Password input is hidden for security
Full Transcript
The passwd command is used to change a user's password on Linux. When you run passwd, it first asks you to enter your current password to confirm your identity. Then it asks you to enter a new password twice to make sure you typed it correctly. If the two new passwords match, the system updates your password and shows a success message. If they don't match, it shows an error and asks you to enter the new password again. Passwords are not shown on screen as you type for security. This process ensures your password is changed safely and correctly.

Practice

(1/5)
1. What does the passwd command do in Linux?
easy
A. It changes the password of a user securely.
B. It lists all users on the system.
C. It creates a new user account.
D. It deletes a user account.

Solution

  1. Step 1: Understand the purpose of passwd

    The passwd command is designed to change user passwords securely on Linux systems.
  2. Step 2: Compare options with command function

    Options B, C, and D relate to user management but not password changes. Only It changes the password of a user securely. correctly describes passwd.
  3. Final Answer:

    It changes the password of a user securely. -> Option A
  4. Quick Check:

    passwd changes passwords = A [OK]
Hint: Remember: passwd is for changing passwords only [OK]
Common Mistakes:
  • Confusing passwd with user creation commands
  • Thinking passwd lists users
  • Assuming passwd deletes accounts
2. Which of the following is the correct syntax to change the password for user alice as root?
easy
A. passwd -p alice
B. passwd -u alice
C. passwd --change alice
D. passwd alice

Solution

  1. Step 1: Recall root usage of passwd

    Root can change any user's password by running passwd username.
  2. Step 2: Analyze options for correct syntax

    Only passwd alice uses the correct syntax. Options A, B, and C use invalid or non-existent flags.
  3. Final Answer:

    passwd alice -> Option D
  4. Quick Check:

    Root changes user password with passwd username = D [OK]
Hint: Use passwd username as root to change others' passwords [OK]
Common Mistakes:
  • Adding wrong flags like -u or -p
  • Using --change which is not a valid option
  • Trying to change password without specifying username as root
3. What will happen if a normal user runs the command passwd root?
medium
A. The root password will be changed immediately.
B. The user will be prompted to enter the current root password.
C. The command will fail with a permission error.
D. The user's own password will be changed instead.

Solution

  1. Step 1: Understand user permissions for passwd

    Only root can change other users' passwords. Normal users cannot change root's password.
  2. Step 2: Predict command behavior for normal user

    When a normal user tries passwd root, the system denies permission and shows an error.
  3. Final Answer:

    The command will fail with a permission error. -> Option C
  4. Quick Check:

    Normal user cannot change root password = A [OK]
Hint: Only root can change other users' passwords; others get permission error [OK]
Common Mistakes:
  • Assuming normal user can change root password
  • Thinking user will be asked root's current password
  • Believing user's own password changes instead
4. You run passwd alice as root but get the error: passwd: Authentication token manipulation error. What is the most likely cause?
medium
A. The password entered does not meet complexity rules.
B. You forgot to run the command with sudo or as root.
C. The user alice does not exist.
D. The passwd command is not installed.

Solution

  1. Step 1: Understand the error meaning

    The error usually means insufficient permissions to update password files.
  2. Step 2: Identify cause based on command context

    If not run as root or with sudo, passwd cannot change another user's password, causing this error.
  3. Final Answer:

    You forgot to run the command with sudo or as root. -> Option B
  4. Quick Check:

    Permission error means missing root privileges = C [OK]
Hint: Run passwd with root or sudo to avoid permission errors [OK]
Common Mistakes:
  • Assuming user does not exist without checking
  • Thinking password complexity causes this error
  • Believing passwd is missing from system
5. 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
A. for user in $(cat users.txt); do echo -e "NewPass123\nNewPass123" | passwd $user; done
B. while read user; do echo "NewPass123" | passwd --stdin $user; done < users.txt
C. for user in users.txt; do passwd $user NewPass123; done
D. cat users.txt | passwd -p NewPass123

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]
Hint: 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
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard