The passwd
command in Linux is used to set, change, and manage passwords and user account settings. Below is a detailed explanation of its usage, options, and examples, including expected outputs.
passwd [options] [username]
- If no username is specified, it changes the password for the currently logged-in user.
To see all available options:
passwd --help
- 📌 Output: Displays help information about
passwd
options.
useradd nikhil
useradd ai
- 📌 Output: No output if successful. ✅
- 🔍 Verify: Check user entries using:
cat /etc/passwd | grep -E "nikhil|ai"
To check user details in system files:
grep -E " (nikhil|ai)" /etc/passwd /etc/shadow /etc/group /etc/gshadow
- 📌 Output: Displays entries for
nikhil
andai
in system files.
To set a password for nikhil
:
passwd nikhil
- 📌 Input:
Changing password for nikhil. Enter new UNIX password: Retype new UNIX password:
- ✅ Output:
passwd: password updated successfully
To remove a user's password:
passwd -d nikhil
- 📌 Output: No output if successful. ✅
- 🔍 Effect: The account becomes password-less, meaning the user can log in without a password.
To lock the account of nikhil
:
passwd -l nikhil
- 📌 Output:
passwd: password expiry information changed.
- 🔍 Effect: The account is locked, preventing logins.
To unlock nikhil
's account:
passwd -u nikhil
- 📌 Output:
passwd: password expiry information changed.
- 🔍 Effect: The user can log in again.
To check the password status of nikhil
:
passwd -S nikhil
- 📌 Output:
nikhil P 01/06/2025 0 99999 7 -1
- Explanation:
P
→ Password is set ✅01/06/2025
→ Last password change date 📅0 99999 7 -1
→ Expiration and aging information
To force nikhil
to change the password on next login:
passwd -e nikhil
- 📌 Output: No output if successful. ✅
To set a specific expiration date:
passwd -e 2025-12-13 nikhil
- 📌 Output: No output if successful. ✅
To manually edit password settings in the shadow file:
vim /etc/shadow
⚠️ Warning: Editing this file incorrectly may lock users out of the system. Use with caution.
📌 Command | 📝 Description | 🎯 Expected Output |
---|---|---|
passwd --help |
📖 Display help info | Shows help text |
useradd nikhil |
👤 Create user nikhil |
No output ✅ |
useradd ai |
👤 Create user ai |
No output ✅ |
`grep -E " (nikhil | ai)" ...` | 🔍 Check user entries |
passwd nikhil |
🔑 Set password for nikhil |
Prompts for new password |
passwd -d nikhil |
❌ Remove password for nikhil |
No output ✅ |
passwd -l nikhil |
🔒 Lock user account | Password expiry info changed |
passwd -u nikhil |
🔓 Unlock user account | Password expiry info changed |
passwd -S nikhil |
📊 Check password status | Shows status of nikhil 's password |
passwd -e nikhil |
⏳ Expire password | No output ✅ |
passwd -e 2025-12-13 nikhil |
📅 Set expiration date | No output ✅ |
vim /etc/shadow |
Opens file in vim |
This guide helps system administrators efficiently manage user passwords and account settings in Linux environments. 🐧💻🚀
This version makes it easier to read and understand by using emojis. Let me know if you’d like any modifications! 😊