Linux Password Policies — Securing User Authentication¶
Passwords are the first line of defense in Linux security. Weak passwords or poorly configured password policies can lead to unauthorized access, privilege escalation, and security breaches. Linux provides built-in mechanisms to enforce password complexity, expiration, aging, and account locking to protect systems from misuse.
Learning Path¶
Course Progress
What You'll Learn¶
After completing this lesson, you'll be able to:
- Understand Linux password policies
- Manage user passwords
- Configure password aging
- Set password expiration
- Lock and unlock user accounts
- Understand the
/etc/shadowfile - Apply password security best practices
- Enforce enterprise password policies
Prerequisites¶
Complete:
- Module 1 – Linux Fundamentals
- Module 2 – Linux Command Line Essentials
- Module 3 – Text Processing
- Module 4 – File Management and Permissions
- Module 5 Lessons 1–3
Why Learn Password Policies?¶
Imagine a production Linux server.
A user account has:
- Password:
admin123 - Never expires
- Shared by multiple administrators
This creates a serious security risk.
Linux password policies help enforce:
- Strong passwords
- Password expiration
- Password history
- Account security
- Compliance requirements
What is a Password Policy?¶
A password policy defines rules such as:
- Minimum password length
- Password complexity
- Password expiration
- Password aging
- Password reuse restrictions
- Account locking
These policies reduce the risk of unauthorized access.
The Password Lifecycle¶
Create Password
│
▼
Password Active
│
▼
Password Expires
│
▼
User Changes Password
│
▼
New Password Active
Changing a Password¶
Change your own password.
Example:
Change Another User's Password¶
Administrator only.
Password Information¶
Display password aging information.
Example:
Password Aging¶
Linux supports:
- Minimum password age
- Maximum password age
- Warning period
- Inactive period
These settings help enforce regular password updates.
Configure Password Expiration¶
Example:
Meaning:
Minimum Password Age¶
Prevent immediate password changes.
Meaning:
Warning Before Expiration¶
Warn users before expiration.
Meaning:
Account Expiration¶
Set account expiration.
Disable expiration.
Lock a User Account¶
Temporarily disable password authentication.
Check status.
Unlock a User Account¶
Force Password Change¶
Require the user to change their password at the next login.
Understanding /etc/shadow¶
Linux stores password information in:
View (requires elevated privileges).
Example:
Fields include:
- Username
- Password hash
- Last password change
- Minimum age
- Maximum age
- Warning period
- Inactive period
- Account expiration
Passwords are stored as hashed values, not plain text.
Difference Between /etc/passwd and /etc/shadow¶
| File | Purpose |
|---|---|
/etc/passwd | User account information |
/etc/shadow | Password hashes and aging information |
Common Commands¶
Change password.
Display aging.
Set maximum age.
Set minimum age.
Set warning days.
Lock account.
Unlock account.
Force password reset.
Password Complexity¶
Many Linux systems enforce password complexity using PAM modules.
Common requirements include:
- Minimum length
- Uppercase letters
- Lowercase letters
- Numbers
- Special characters
- Password history
We'll learn how Linux enforces these policies in the PAM Overview lesson later in this module.
Real Production Examples¶
Force password reset after onboarding.
Lock a terminated employee's account.
Set a 90-day password expiration policy.
Review password aging.
Production Perspective¶
Password policies are essential for:
- Enterprise Linux servers
- Cloud virtual machines
- SSH access
- Compliance standards (CIS, ISO 27001, PCI-DSS)
- Financial systems
- Healthcare systems
- Government environments
Strong password policies reduce the risk of credential compromise.
Hands-on Lab¶
Task 1¶
View password aging information.
Task 2¶
Change your password.
Task 3¶
View your account information again.
Task 4¶
Display your password status.
Task 5¶
View the shadow file.
Observe the password hash format.
Task 6¶
Lock a test user account.
(Replace testuser with an existing non-production user.)
Task 7¶
Unlock the account.
Task 8¶
Force a password change at the next login.
Command Deep Dive¶
| Command | Purpose | Production Example |
|---|---|---|
passwd | Change password | User management |
passwd -l | Lock account | Disable access |
passwd -u | Unlock account | Restore access |
passwd -e | Expire password | Force reset |
passwd -S | View password status | Auditing |
chage | Manage password aging | Compliance |
Production Troubleshooting Scenario¶
Scenario
A user cannot log in.
Error:
Investigation:
The password has exceeded the maximum age.
Solution:
Reset the password.
or require a password change on the next login.
The user successfully regains access after updating the password.
Best Practices¶
- Enforce strong password complexity.
- Set password expiration policies for enterprise accounts.
- Lock accounts that are no longer in use.
- Force password changes for newly created users.
- Protect the
/etc/shadowfile. - Regularly audit password policies.
Common Mistakes¶
❌ Using weak or predictable passwords.
✅ Avoid using weak or predictable passwords when a safer approach exists.
❌ Sharing user accounts and passwords.
✅ Avoid this mistake: sharing user accounts and passwords.
❌ Allowing passwords to never expire in enterprise environments without a justified exception.
✅ Do not allow passwords to never expire in enterprise environments without a justified exception.
❌ Granting unnecessary access to the /etc/shadow file.
✅ Avoid this mistake: granting unnecessary access to the /etc/shadow file.
Interview Questions¶
Beginner¶
- Which command changes a user's password?
- What is the purpose of
/etc/shadow? - How do you lock a user account?
- What is password aging?
Intermediate¶
- Explain the difference between
/etc/passwdand/etc/shadow. - How do you configure password expiration?
- How do you force a password change at the next login?
- What information does
chage -ldisplay?
Architect Level¶
- How would you enforce password policies across hundreds of Linux servers?
- How do password policies help meet compliance requirements?
- When would you choose SSH key authentication instead of passwords?
Summary¶
In this lesson, you learned:
- Password management
- Password aging
- Password expiration
- Account locking
- Account unlocking
/etc/shadow- Enterprise password policies
- Security best practices
Strong password policies are a critical component of Linux security. They help protect systems against unauthorized access while supporting organizational security standards and compliance requirements.
Key Takeaways¶
- Use
passwdto manage passwords. - Use
chageto configure password aging. - Store password hashes securely in
/etc/shadow. - Lock unused accounts.
- Force password changes for new users.
- Apply strong password policies for enterprise environments.
What's Next?¶
Environment Variables in Linux — Configuring the Linux Environment
You'll explore:
- Local variables
- Environment variables
PATHHOMEUSERSHELLHOSTNAMEexportunset- Best practices for configuring application environments
Environment variables are fundamental to Linux, scripting, DevOps automation, Docker, Kubernetes, and cloud-native applications.