Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
$ als gewone gebruiker# als root (of met sudo)
The quick answer
Step by step
- Lock everything that gives access:
| Command | Stops |
|---|---|
usermod -L bob | Password logins. |
usermod -e 1 bob (or chage -E 0 bob) | All logins via PAM — also SSH keys. |
usermod -s /sbin/nologin bob | Interactive shells. |
gpasswd -d bob wheel (sudo on Ubuntu) | Admin rights via sudo. |
mv ~bob/.ssh/authorized_keys …disabled | SSH keys (belt and braces). |
- End running sessions and jobs:
loginctl terminate-user bob
pkill -KILL -u bob
crontab -l -u bob
crontab -r -u bob
systemctl list-timers --all | grep -i bobBefore removing a crontab, check whether a real job runs as this user (it may need a new owner).
- Other places the person had access — the Linux account is only one door: VPN, Git (GitHub/GitLab) and cloud accounts, shared passwords and API tokens they knew (rotate them), deploy keys, Kubernetes kubeconfigs.
- Check what is left:
passwd -S bob
bob LK 2026-11-19 0 99999 7 -1 (Password locked.)
sudo -l -U bob
User bob is not allowed to run sudo on web1.
ps -u bob- Unlock (the person comes back, or it was a mistake):
usermod -U -e '' -s /bin/bash bob- Delete later — after the retention time, archive the home folder, then remove the user and find files outside the home:
tar -czf /archive/home-bob-2026-11-19.tar.gz -C /home bob
userdel -r bob
find / -xdev -nouser -print 2>/dev/nullMany servers? Do it with Ansible (ansible.builtin.user with expires, password_lock, state: absent) or central identity (IdM/FreeIPA, Active Directory) — one place to disable.
Check that it worked
From another machine, SSH with the person's key is refused:
ssh -i bob_key bob@web1
bob@web1: Permission denied (publickey).passwd -S shows LK, chage -l shows the account expired, sudo -l -U bob shows no rights, and ps -u bob shows no processes.
Common problems
| Problem | Cause | Fix |
|---|---|---|
| The person still logs in with an SSH key | Only the password was locked. | Expire the account (usermod -e 1) and remove authorized_keys. |
| Still logged in after locking | Existing sessions are not ended by locking. | loginctl terminate-user, pkill -u. |
| A job broke after removing the user | A cron job or service ran as this person. | Move jobs to a service account before deleting people. |
userdel: user bob is currently used by process … | Processes still running. | Stop them first; then userdel. |
| Account works on other servers | Local accounts on each server. | Use Ansible for all servers, or central identity. |
| Files of the deleted user belong to a new user later | UID reused. | Find and re-own -nouser files after deletion. |
Go further
- Command pages: usermod, chage, passwd, userdel, loginctl, gpasswd.
- Next how-tos: Set password rules and expiry, See who logged in and when, Create a user with sudo rights.
- Learn it: RHCSA — usermod, RHCSA — Password aging, RH124 — Manage users.
- Practise: Lab: create users and groups with password rules.
1Why is passwd -l not enough to stop a user?
It locks only the password; SSH key logins still work — expire the account too.