0
0
Linux-cliHow-ToBeginner · 3 min read

How to Change Password in Linux: Simple Command Guide

To change your password in Linux, use the passwd command in the terminal. It will prompt you to enter your current password and then the new password twice to confirm.
📐

Syntax

The basic syntax to change a password in Linux is:

  • passwd: Changes the password for the current user.
  • passwd username: Changes the password for the specified user (requires root privileges).

When you run the command, it will ask for the current password and then the new password twice for confirmation.

bash
passwd
passwd username
💻

Example

This example shows how a regular user changes their own password using the passwd command.

bash
passwd
Output
Changing password for user yourusername. Current password: New password: Retype new password: passwd: password updated successfully
⚠️

Common Pitfalls

  • Entering the wrong current password will prevent the change.
  • New passwords must match exactly when typed twice.
  • Some systems enforce password complexity rules; weak passwords may be rejected.
  • Changing another user's password requires root access (use sudo passwd username).
bash
Wrong way:
passwd username
# Without sudo, this will fail if you are not root

Right way:
sudo passwd username
📊

Quick Reference

CommandDescription
passwdChange your own password
passwd usernameChange password for another user (root only)
sudo passwd usernameChange another user's password with root privileges
passwd -l usernameLock a user's password (disable login)
passwd -u usernameUnlock a user's password

Key Takeaways

Use the passwd command to change passwords in Linux.
You must enter your current password before setting a new one.
Changing another user's password requires root privileges.
Ensure new passwords match and meet system complexity rules.
Use sudo passwd username to change passwords for other users.