passwd Command in Linux
Build an AI-First Career, Master the Complete Skillset
Choose from our industry-leading programs designed for career success
Modern Software and AI Engineering Program
Master full-stack development with AI integration
+1000 moreModern Data Science and ML with specialisation in AI
Advanced data science techniques with AI specialization
+1000 moreAdvanced AIML with Specialisation in Agentic AI
Deep dive into AIML with focus on Agentic systems
+1000 moreDevOps, Cloud & AI Platform Engineering
Build and manage AI-powered cloud infrastructure
+1000 moreAI Engineering Advanced Certification by IIT-Roorkee
Premier AI engineering certification from IIT-Roorkee
AI Forward Deployed Engineer Program
Full-stack engineering, production AI and client-facing consulting
+1000 moreOverview
The passwd command in Linux is a powerful tool used for managing user passwords. It is primarily designed to change the user's password but also allows administrators to modify other password-related parameters such as expiration date and locked status. In this article, we will discuss the syntax, options, and various use cases of the passwd command.
Linux passwd Command Syntax
The syntax for the passwd command is as follows:
Where:
- options: Options are flags that modify the behavior of the passwd command. They can be used to change password expiration settings, lock/unlock user accounts, or display account status.
- user: The user whose password is being modified. If no user is specified, the command will assume the user running the command.
passwd Command Options:
- -l, --lock: Locks the specified user's account, preventing them from logging in.
- -u, --unlock: Unlocks the specified user's account, allowing them to log in again.
- -e, --expire: Immediately expires the specified user's password, requiring them to set a new one on their next login.
- -S, --status: Displays the password status of the specified user.
Example Usages
-
Change current user's password:
Output:
Explanation: The passwd command without any arguments allows the current user to change their password. They will be prompted to enter their current password and then enter the new password twice.
-
Lock a user account:
Output:
Explanation: The -l flag locks the specified user's account, preventing them from logging in. This command requires root privileges (sudo).
How Scaler Transformed Careers in Different Fields
Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.
Tips
-
Always use strong and unique passwords for each user account.
-
Regularly change passwords and enforce password expiration policies.
Advanced Use Cases of passwd Command in Linux
-
Unlock a user account:
Output:
Explanation: The -u flag unlocks the specified user's account, allowing them to log in again. This command requires root privileges (sudo).
-
Expire a user's password:
Output:
Explanation: The -e flag immediately expires the specified user's password, forcing them to set a new one on their next login. This command requires root privileges (sudo).
-
Display password status:
Output:
Explanation: The -S flag displays the password status of the specified user. The output shows the username, password status (P for set), last password change date, minimum age, maximum age, warning period, and inactivity period. This command requires root privileges (sudo).
Turn Learning into Career Growth
Conclusion
-
passwd command is used to manage user passwords in Linux.
-
It allows changing, locking, unlocking, and expiring passwords.
-
Always use strong and unique passwords for security purposes.
-
Regularly update passwords and enforce expiration policies.