passwd Command in Linux: Change User Passwords

By 

Updated on

6 min read

passwd Command in Linux

In Linux, user passwords are changed with the passwd command. The encrypted passwords and aging information are stored in the /etc/shadow file.

As a regular user, you can only change your own password. The root user and users with sudo privileges can change another user’s password and control how the password can be used or changed.

When changing a password, make sure you use a strong and unique password. A strong password has at least 16 characters and contains at least one uppercase letter, one lowercase letter, one number, and one special character.

The instructions in this guide work on any Linux distribution, including Ubuntu, Debian, and CentOS.

passwd Command Syntax

The basic passwd syntax is:

txt
passwd [OPTIONS] [USERNAME]

Run passwd without a username to change your own password. Run it as root, or with sudo, followed by a username to change another user’s password.

Changing Your Own Password

To change your own password, run passwd without any arguments:

Terminal
passwd

You will be prompted to enter your current password. If correct, the command will ask you to enter and confirm the new password:

output
Changing password for linuxize.
Current password:
New password:
Retype new password:
passwd: password updated successfully
Info
Passwords are not displayed on the screen when you type them.

Log in again using the new password.

Changing Another User’s Password

To change the password of another user account, run the passwd command followed by the username. For example, to change the password of a user named sansa:

Terminal
sudo passwd sansa

You will be prompted to enter and confirm the new password:

output
New password:
Retype new password:
passwd: password updated successfully

Unlike changing your own password, you are not asked for the current password.

Changing the Root Password

To change the root password, run:

Terminal
sudo passwd root

Enter and confirm the new root password when prompted.

If you do not know the current root password and have sudo access, this is the way to reset it.

Info
On Ubuntu, the root account is locked by default. Setting a root password enables local root login, but SSH root login may still be disabled in sshd_config.

Removing a Password (Empty Password)

To remove a user’s password (set it to empty), use the -d option:

Terminal
sudo passwd -d sansa

An empty password allows passwordless login, so use this only in controlled environments.

Forcing a Password Change at Next Login

To force a user to change their password the next time they log in, expire the password with the --expire option:

Terminal
sudo passwd --expire sansa

The next time the user tries to log in, they will see a message requiring them to set a new password:

output
WARNING: Your password has expired.
You must change your password now and login again!
Current password:
New password:
Retype new password:
passwd: password updated successfully
Connection to 192.168.1.10 closed.

You can also use chage to achieve the same result:

Terminal
sudo chage -d 0 sansa

Password Aging Policy with chage

The chage command controls password aging. It allows you to set expiration dates, minimum and maximum password age, and warning periods.

To view the password aging information for a user:

Terminal
sudo chage -l sansa
output
Last password change                    : Feb 03, 2026
Password expires                        : never
Password inactive                       : never
Account expires                         : never
Minimum number of days between password change  : 0
Maximum number of days between password change  : 99999
Number of days of warning before password expires : 7

Common chage options:

  • Set the maximum number of days a password is valid (e.g., 90 days):

    Terminal
    sudo chage -M 90 sansa
  • Set the minimum number of days between password changes (e.g., 7 days):

    Terminal
    sudo chage -m 7 sansa
  • Set the number of warning days before the password expires (e.g., 14 days):

    Terminal
    sudo chage -W 14 sansa
  • Set an account expiration date:

    Terminal
    sudo chage -E 2026-12-31 sansa

Locking and Unlocking a User Account

To lock a user account so they cannot log in:

Terminal
sudo passwd -l sansa
output
passwd: password expiry information changed.

This prepends a ! to the encrypted password in /etc/shadow, making it invalid.

To unlock the account:

Terminal
sudo passwd -u sansa

To check whether an account is locked:

Terminal
sudo passwd -S sansa

The second field shows L for locked or P for a usable password.

Quick Reference

TaskCommand
Change your own passwordpasswd
Change another user’s passwordsudo passwd username
Change the root passwordsudo passwd root
Force password change at next loginsudo passwd --expire username
View password aging infosudo chage -l username
Set max password age (90 days)sudo chage -M 90 username
Set min password age (7 days)sudo chage -m 7 username
Set warning days (14 days)sudo chage -W 14 username
Set account expiration datesudo chage -E YYYY-MM-DD username
Lock a user accountsudo passwd -l username
Unlock a user accountsudo passwd -u username
Check account lock statussudo passwd -S username

FAQ

How do I change the root password if I forgot it?
If you have sudo access, run sudo passwd root. If you do not have sudo access, boot into single-user mode or a recovery environment to reset it.

What are the password requirements in Linux?
By default, Linux uses PAM (Pluggable Authentication Modules) to enforce password quality. The default rules depend on the distribution and PAM configuration in /etc/pam.d/. You can install libpam-pwquality (or pam_pwquality on RHEL-based systems) to configure minimum length, character classes, and other requirements.

What is the difference between passwd --expire and chage -d 0?
Both commands force the user to change their password at the next login. passwd --expire is simpler; chage -d 0 sets the “last password change” date to epoch 0, which has the same effect.

Can I change a password non-interactively in a script?
Yes. Pipe the new password to chpasswd:

Terminal
echo "username:newpassword" | sudo chpasswd

What does locking an account with passwd -l do?
It prepends ! to the hashed password in /etc/shadow, making password authentication impossible. It does not disable SSH key-based login. To fully disable an account, use usermod -s /usr/sbin/nologin username as well.

Conclusion

The passwd command handles password changes for your own account and other users. Use chage to manage password aging policies like expiration and minimum age. To lock or unlock accounts, use passwd -l and passwd -u.

For more information, type man passwd or man chage in your terminal.

If you have any questions, feel free to leave a comment below.

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page