userdel Command Cheat Sheet
userdel modifies the system account files, deleting all entries that refer to the user name.
Synopsis
userdel [options] LOGIN
Basic Deletion (Usually Incomplete)
sudo userdel john
/etc/passwd but leaves their files behind:
- /home/john remains.
- /var/mail/john remains.
Complete Deletion (-r)
Remove the home directory and mail spool. Highly Recommended.
sudo userdel -r john
Force Deletion (-f)
Forces the removal of the user account, even if the user is still logged in.
sudo userdel -f john
sudo pkill -u john
sudo userdel -r john
Troubleshooting
"user john is currently used by process 1234"
The user has running processes.
- Kill processes:
sudo killall -u john - Retry:
sudo userdel -r john
"group john not removed because it is not the primary group of another user"
userdel typically removes the user's primary group if no one else is in it. If not, remove manually:
sudo groupdel john
Related Files
/etc/passwd: User info/etc/shadow: Password hashes/etc/group: Group info