Site icon New Generation Enterprise Linux

Stop locked-out service accounts from leaving your system wide open

User & Group Management

Stop locked-out service accounts from leaving your system wide open

đź§© The Challenge

Dealing with a service account that still has valid SSH keys hanging around after it’s been disabled is a security nightmare waiting to happen. You change the password, but the keys keep working, and you’re left wondering how someone is still logged in.

đź’ˇ The Fix

The right move is to lock the account and purge the authorized_keys file in one go so you don’t leave any backdoors behind. It keeps the audit trail clean without letting old credentials bypass your changes.

usermod -L -s /usr/sbin/nologin username && rm -rf /home/username/.ssh

⚙️ Why It Works

By flipping the shell to nologin and locking the password, you effectively brick any interactive entry, while wiping the .ssh directory ensures that public key authentication can’t sneak around your restrictions.

🚀 Pro-Tip: Check /etc/shadow for that exclamation mark after the username to confirm the account is actually locked.

Linux Tips & Tricks | © ngelinux.com | 11/20/2026

0 0 votes
Article Rating
Exit mobile version