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: usermod -e 1 shuts an account out, SSH keys included, a real security lock

Security
~/tips/tip-security-usermod-expiredate-disable-account

sudo usermod --expiredate 1 bob

Disables an account completely, so key logins stop too, without deleting anything.

Locking a password does not stop someone with an SSH key. When a person leaves or an account must go dark right now, I’d expire the account itself.

An account with an expiry date in the past is refused by PAM at every login, whatever the method. Setting the date with --expiredate, or -e for short, to day 1 (2 January 1970) does exactly that:

sudo usermod --expiredate 1 bob
sudo chage -l bob | grep 'Account expires'

The second line confirms it. You should see Account expires : Jan 02, 1970. Files, crontab and home folder stay where they are, so you can still look through them or hand them over later.

To give the account back, clear the date again:

sudo usermod --expiredate '' bob

I like this better than deleting a user in a hurry. Deleting loses the evidence and frees the UID for the next new account, which can then end up owning the old files.

Keep in mind that this only blocks new logins. Sessions that are already open keep running, so check w and end them with loginctl terminate-user bob. Processes the user left behind, like a tmux session or a cron job, are a separate story too.

Further reading: usermod(8) manual page, chage(1) manual page

More Security tips tcpdump -nn -r capture.pcap port 53 mkcert -install Strict-Transport-Security: max-age=0 Referrer-Policy: strict-origin-when-cross-origin wp super-admin list All Security tips (79) All topics

Link