Skip to content

Latest commit

 

History

History
164 lines (132 loc) · 4.41 KB

Passwd-Command-in-Linux.md

File metadata and controls

164 lines (132 loc) · 4.41 KB

🔐 Linux passwd Command – Manage User Passwords & Accounts

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.

📌 Basic Syntax

passwd [options] [username]
  • If no username is specified, it changes the password for the currently logged-in user.

⚙️ Common Options & Examples

1️⃣ Help Menu 📖

To see all available options:

passwd --help
  • 📌 Output: Displays help information about passwd options.

2️⃣ Create New Users 👤

useradd nikhil
useradd ai
  • 📌 Output: No output if successful. ✅
  • 🔍 Verify: Check user entries using:
    cat /etc/passwd | grep -E "nikhil|ai"

3️⃣ Check User Entries 🔎

To check user details in system files:

grep -E " (nikhil|ai)" /etc/passwd /etc/shadow /etc/group /etc/gshadow
  • 📌 Output: Displays entries for nikhil and ai in system files.

4️⃣ Set a Password 🔑

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
    

5️⃣ Remove a User's Password ❌🔑

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.

6️⃣ Lock a User Account 🔒

To lock the account of nikhil:

passwd -l nikhil
  • 📌 Output:
    passwd: password expiry information changed.
    
  • 🔍 Effect: The account is locked, preventing logins.

7️⃣ Unlock a User Account 🔓

To unlock nikhil's account:

passwd -u nikhil
  • 📌 Output:
    passwd: password expiry information changed.
    
  • 🔍 Effect: The user can log in again.

8️⃣ Check Password Status 📊

To check the password status of nikhil:

passwd -S nikhil
  • 📌 Output:
    nikhil P 01/06/2025 0 99999 7 -1
    
  • Explanation:
    • PPassword is set
    • 01/06/2025 → Last password change date 📅
    • 0 99999 7 -1 → Expiration and aging information

9️⃣ Set Password Expiry ⏳

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. ✅

🔟 Edit Shadow File ⚠️ (Manual Editing)

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 Summary Table

📌 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 ⚠️ Edit shadow file 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! 😊