Deleting a user is a root task. The decision is whether to keep their files. To remove the account and its home directory and mail spool:
sudo userdel -r deploy
Without -r, userdel deploy removes the account but leaves /home/deploy behind. That is sometimes what you want (keep their work, free the login), but more often it just leaves orphaned files owned by a now-missing UID.
Before you delete: check for running processes and shared files
A user can own files and processes all over the system, not just in their home directory. Deleting the account leaves those owned by a bare numeric UID, which a future new user could inherit.
# First, check: are they logged in or running anything?
who | grep deploy
ps -u deploy
# Then, if you are sure, end their processes
sudo pkill -u deploy
# Find everything they own outside their home
sudo find / -user deploy -not -path '/proc/*' 2>/dev/nulluserdel refuses to remove a user who is currently logged in or has running processes, which is a feature; check with who/ps, then end the processes first (or use userdel -f to force, which is riskier). The find sweep is the step people skip and regret. Reassign or remove what it finds before (or after) deleting the account. The owner-search syntax is covered in find files by owner and permission.
Lock instead of delete (often the better move)
For a departing team member, deleting the account immediately can break cron jobs, mail, and file ownership. Locking it keeps everything in place while blocking access:
sudo usermod -L deploy # lock the password
sudo usermod -s /usr/sbin/nologin deploy # block the shell tooYou get an audit trail and the option to reverse it. See lock and unlock a user account for the full set. Delete only once you are sure nothing depends on the account.
Remove the group too, if it was theirs
userdel removes the user's primary group if no one else uses it, but a shared group it merely belonged to stays. To remove a now-empty group:
sudo groupdel developersFAQ
See also
- How to Create a User on Linux: the reverse operation.
- Lock and unlock a user account: the safer alternative to deletion.
- Find files by owner, group, or permission: track down what a user owns before removing them.
- How to change file owner and group (chown): reassign their orphaned files.
Sources
Authoritative references this article was fact-checked against.





