0
0
Linux CLIscripting~3 mins

passwd (change password) in Linux CLI - Commands & Configuration

Choose your learning style9 modes available
Introduction
Sometimes you need to change your login password on a Linux system to keep your account secure or update it after it expires. The passwd command lets you do this easily from the command line.
When you want to update your own user password for security reasons.
When an administrator needs to reset another user's password.
When a password has expired and you are prompted to change it at login.
When setting a new password after creating a user account.
When you suspect your password has been compromised and want to change it immediately.
Commands
This command lets the current user change their own password. It will prompt you to enter your current password first, then ask for the new password twice to confirm.
Terminal
passwd
Expected OutputExpected
Changing password for user yourusername. Current password: New password: Retype new password: passwd: password updated successfully
As an administrator, this command changes the password for user 'alice' without needing her current password. It will prompt for the new password twice.
Terminal
sudo passwd alice
Expected OutputExpected
Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully
sudo - Run the command with administrator privileges to change another user's password.
Key Concept

If you remember nothing else, remember: passwd securely updates user passwords by prompting for the current password (unless run as admin) and confirming the new password twice.

Common Mistakes
Typing the new password only once without confirmation.
The passwd command requires you to enter the new password twice to avoid typos and ensure accuracy.
Always enter the new password twice exactly as prompted.
Trying to change another user's password without sudo or root privileges.
Without proper permissions, passwd will not allow changing other users' passwords.
Use sudo before passwd to gain the necessary permissions.
Entering the wrong current password when changing your own password.
The command will reject the change if the current password is incorrect.
Make sure to enter your current password correctly before setting a new one.
Summary
Use 'passwd' to change your own password securely by entering your current password and confirming the new one.
Administrators can change other users' passwords using 'sudo passwd username' without needing the current password.
Always enter the new password twice to confirm and avoid mistakes.