userdel Command
Intermediate User Management man(1)Delete a user account
๐ 118 views
๐
Updated: Apr 30, 2026
SYNTAX
userdel [OPTION]... USERNAME
What Does userdel Do?
userdel removes a user account from the system. It deletes the user entry from /etc/passwd and /etc/shadow, and optionally removes the home directory and mail spool.
userdel requires root privileges. Without -r, it only removes the user account, leaving home directory and files intact. With -r, it removes everything.
Before deleting a user, it is good practice to check for running processes (ps -u username) and transfer ownership of important files (find / -user username).
userdel requires root privileges. Without -r, it only removes the user account, leaving home directory and files intact. With -r, it removes everything.
Before deleting a user, it is good practice to check for running processes (ps -u username) and transfer ownership of important files (find / -user username).
Options & Flags
| Option | Description | Example |
|---|---|---|
| -r | Remove home directory and mail spool | sudo userdel -r olduser |
| -f | Force removal (even if user is logged in) | sudo userdel -f baduser |
| -Z | Remove SELinux user mapping | sudo userdel -Z user |
Practical Examples
#1 Remove user only
Removes the account but keeps home directory and files.
$ sudo userdel olduser#2 Remove user and files
Removes the account, home directory, and mail spool.
$ sudo userdel -r olduser#3 Force remove logged-in user
Force removes even if the user is currently logged in or has running processes.
$ sudo userdel -f baduser#4 Full cleanup procedure
Kills processes, removes user, and cleans up temp files.
$ sudo killall -u olduser; sudo userdel -r olduser; sudo find /tmp -user olduser -delete#5 Check before deleting
Check for running processes and owned files before deletion.
$ ps -u olduser; find /var/www -user olduserTips & Best Practices
Kill processes first: userdel may fail if the user has running processes. Kill them first: sudo killall -u username.
Backup before -r: userdel -r permanently deletes the home directory. Back up important data first: tar czf /backup/user.tar.gz /home/user.
Files remain without -r: Without -r, home directory files remain as orphaned (owned by deleted UID). Clean up with find / -nouser.
Frequently Asked Questions
How do I delete a user?
sudo userdel username removes the account. Add -r to also delete the home directory: sudo userdel -r username.
What happens to the user files?
Without -r, files in home directory remain (owned by the old UID number). With -r, home directory is deleted.
Why does userdel fail?
The user may have running processes. Kill them first: sudo killall -u username, then retry userdel.
Related Commands
More User Management Commands
Download User Management Cheat Sheet
View all 31 Linux command cheat sheets โMaster Linux with Professional eBooks
Curated IT eBooks covering Linux, DevOps, Cloud, and more
Browse Books โ