Skip to content

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
This removes the user from /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
Note: It is safer to kill their processes first.

sudo pkill -u john
sudo userdel -r john

Troubleshooting

"user john is currently used by process 1234"

The user has running processes.

  1. Kill processes: sudo killall -u john
  2. 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

  • /etc/passwd: User info
  • /etc/shadow: Password hashes
  • /etc/group: Group info