Lock (and unlock) a user's password with `usermod -L`
For leaving an employee or pausing an account, `usermod -L` disables password logins in one flag — but it does not stop SSH keys, a subtlety people forget.
Run `sudo usermod -L username` to lock the password and `sudo usermod -U username` to unlock it again.
01Command
Command
$ sudo usermod -L username02What it does
`-L` puts a `!` in front of the hashed password in /etc/shadow, so every password check fails while the account itself, files and UID stay intact — no delete/recreate needed. The forgotten caveat from the man page itself: SSH public-key authentication is unaffected, so a fully disabled user also needs an expired shell (`usermod -s /usr/sbin/nologin username`) or an expired date (`usermod -e 1 username`). `passwd -l` does the same as `-L`, but unlocking it (`passwd -u`) fails for accounts with no password.
03Risk
!Warning: Locking the password does not terminate running sessions or block SSH keys — combine with `usermod -s /usr/sbin/nologin` for a full lockout.
04Undo
Undo
$ sudo usermod -U username05Sources
- usermod(8) — modify a user accountEvidence: Documents -L (prepend ! to encrypted password, disabling it) and -U (unlock); notes SSH key auth may still allow login
Last verified: 2026-09-17 · Category: Security & Privacy