passwd Command in Linux

Learn via video courses
Topics Covered

Build an AI-First Career, Master the Complete Skillset

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program
NSDC Certified

AI Forward Deployed Engineer Program

Full-stack engineering, production AI and client-facing consulting

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program

Overview

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.
Sharpen Your Fundamentals with Free Learning

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

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

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

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

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.