Stop shadow accounts from haunting your system without a proper audit
User & Group Management
Stop shadow accounts from haunting your system without a proper audit
🧩 The Challenge
Dealing with a server migration where you find dozens of stale accounts with weird UID mappings is a nightmare. It’s usually the result of some long-gone dev setting up a test user and forgetting to clean up the mess.
💡 The Fix
Use a quick loop to verify which UID entries in passwd actually lack a corresponding home directory, then dump them to a list for review before you go deleting things blindly.
getent passwd | awk -F: '$3 >= 1000 && $3 < 60000 {print $1, $6}' | while read user home; do [ ! -d "$home" ] && echo "Missing home: $user ($home)"; done
⚙️ Why It Works
This approach pulls the system user list via getent to avoid parsing local files directly, then checks if the defined home directory actually exists on the filesystem. It’s a lifesaver when you are trying to clean up accounts that aren’t hooked into LDAP or AD.
🚀 Pro-Tip: Always pipe that output to a text file and cross-reference it against your team’s current roster before running a mass usermod -L.
Linux Tips & Tricks | © ngelinux.com | 7/31/2026
