brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: passwd -l locks a Linux account password, but SSH keys still work

Linux
~/tips/tip-security-passwd-l-lock-account

sudo passwd -l olduser

Disables a user's password login on Linux, and what else is needed to really block the account.

When someone leaves, or an account looks suspicious, locking the password is the quick first step. It is less complete than the name suggests.

sudo passwd -l olduser
sudo passwd -u olduser

The man page says -l disables the password by changing the stored value to one that matches no possible encrypted value. In practice it puts a ! in front of the hash. A locked user also cannot change their password. -u unlocks it again by restoring the earlier value.

The caveat is in the same man page: the user may still be able to log in with another authentication token, such as an SSH key. Locking the password does not stop key-based SSH logins. To disable the account properly, the man page recommends usermod --expiredate 1, which sets the expiry date to 1970-01-02:

sudo usermod --expiredate 1 olduser
sudo chage -l olduser

The chage -l line shows the account expiry afterwards, so you can check it took effect.

Be careful which account you lock. If you lock the only user with sudo rights, or the one you are logged in as, you may lose access to the machine. Check that another administrator account works first. Also remove the user’s public keys from authorized_keys if they are never coming back, and stop any services or cron jobs running as that user.

Further reading: passwd(1) manual

More Linux tips a2query -m rewrite renice -n 10 -p 4242 cat config.yml | xsel -ib xvfb-run -a your-program --some-flag dpkg --get-selections > packages.txt All Linux tips (261) All topics

Link