Linux tutorial on the passwd command, covering basic and advanced password management with practical examples.
last modified March 3, 2025
The passwd command in Linux is used to manage user passwords. It allows users to change their own passwords and administrators to manage passwords for other users. This tutorial covers basic and advanced usage of passwd with practical examples.
passwd is essential for maintaining system security by ensuring strong password policies and managing user access.
This example demonstrates how to change your own password.
passwd
The passwd command prompts you to enter your current password and then set a new one.
This example shows how an administrator can change another user’s password.
sudo passwd username
Replace username with the target user’s name. The administrator is prompted to enter a new password.
This example demonstrates how to lock a user account.
sudo passwd -l username
The -l option locks the account, preventing the user from logging in.
This example shows how to unlock a previously locked user account.
sudo passwd -u username
The -u option unlocks the account, allowing the user to log in again.
This example demonstrates how to set a password expiry date for a user.
sudo passwd -e username
The -e option forces the user to change their password at the next login.
This example shows how to display the password status for a user.
sudo passwd -S username
The -S option provides information about the password’s status, including whether it is locked or active.
This example demonstrates how to delete a user’s password.
sudo passwd -d username
The -d option removes the password, allowing the user to log in without one.
This example shows how to force a user to change their password at the next login.
sudo passwd -e username
The -e option ensures the user must update their password immediately.
This example demonstrates how to set a minimum password age.
sudo passwd -n 7 username
The -n option sets the minimum number of days before the password can be changed again.
This example shows how to set a maximum password age.
sudo passwd -x 90 username
The -x option sets the maximum number of days the password is valid.
Use Strong Passwords: Always enforce strong password policies to enhance security.
Regularly Update Passwords: Encourage users to update passwords periodically.
Lock Inactive Accounts: Lock accounts of users who no longer need access.
Monitor Password Status: Regularly check password statuses for compliance.
In this article, we have explored various examples of using the passwd command for managing user passwords, including locking, unlocking, and setting password policies.
My name is Jan Bodnar, and I am a passionate programmer with extensive programming experience. I have been writing programming articles since 2007. To date, I have authored over 1,400 articles and 8 e-books. I possess more than ten years of experience in teaching programming.
List all Linux tutorials.