How to Remove a User in Linux

By 

Updated on

7 min read

Remove a user in Linux

When an account is no longer needed, you can remove it from Linux with the userdel command:

Terminal
sudo userdel username

This removes the user account but keeps the home directory and files. To remove the account and the home directory at the same time, use userdel -r:

Terminal
sudo userdel -r username

Linux is a multi-user system, which means that more than one person can interact with the same system at the same time. As a system administrator, you manage users and groups by creating new users , assigning them to groups , and removing accounts when someone leaves the organization or when an account is no longer needed.

The userdel command removes a user account from a Linux system. It deletes the user’s entries from the /etc/passwd and /etc/shadow files.

Only root or users with sudo privileges can delete user accounts.

Quick Reference

TaskCommand
Remove a user and keep home directorysudo userdel username
Remove a user and home directorysudo userdel -r username
Force remove a logged-in usersudo userdel -f username
Kill all user processessudo killall -u username
Remove user’s cron jobssudo crontab -r -u username
Lock a user instead of deletingsudo usermod -L username
Find files with no valid ownersudo find / -nouser
Find files by UIDsudo find / -uid 1001
Verify user was removedid username
Remove user with deluser on Debian/Ubuntusudo deluser --remove-home username

userdel Command Syntax

txt
userdel [OPTIONS] USERNAME

When invoked without options, userdel removes the user account but leaves the home directory and mail spool intact. The command also reads /etc/login.defs; if USERGROUPS_ENAB is set to yes, it deletes the user’s primary group only if no other users belong to it.

Before You Remove a User

Warning
Before you delete a user, back up any important data and make sure the account is not actively used.

Before removing a user, decide what should happen to the account’s files and scheduled tasks. A safe cleanup usually means checking these items first:

  • Back up files from the user’s home directory if they may be needed later.
  • Check whether the user is logged in or has running processes.
  • Remove the user’s cron jobs if the scheduled tasks should not continue.
  • Lock the account instead of deleting it if access only needs to be disabled temporarily.

These checks help you avoid deleting data that still belongs to an active workflow.

Remove a User in Linux

To remove a user account and keep the home directory:

Terminal
sudo userdel username

This removes the user from /etc/passwd and /etc/shadow but keeps the home directory and all user files.

Remove a User and Home Directory

To remove the user account along with the home directory and mail spool, use the -r (--remove) option:

Terminal
sudo userdel -r username
Warning
The -r option permanently deletes the user’s home directory and its contents. Back up any important data before running this command.

Files owned by the user in other locations are not removed. See Finding Orphaned Files below.

Remove a Logged-In User

If the user is still logged in or has running processes , userdel will refuse to remove the account.

First, list the user’s running processes:

Terminal
ps -u username

If you are sure those processes should be stopped, kill all processes belonging to the user:

Terminal
sudo killall -u username

Then delete the user:

Terminal
sudo userdel -r username

Alternatively, use the -f (--force) option to force the removal even if the user is logged in or has running processes:

Terminal
sudo userdel -f username

Use -f carefully. It can leave running processes or files in a confusing state if you remove an account while it is still active.

Removing a User’s Cron Jobs

Deleting a user does not automatically remove their scheduled cron jobs. To remove them:

Terminal
sudo crontab -r -u username

Run this before deleting the user account.

Locking a User Instead of Deleting

If you only need to disable access temporarily, lock the account instead of deleting it:

Terminal
sudo usermod -L username

To unlock it later:

Terminal
sudo usermod -U username

Finding Orphaned Files

After deleting a user, files they owned outside the home directory remain on the system. These files are now owned by the user’s old numeric UID.

To find all files with no valid owner:

Terminal
sudo find / -nouser

To find files owned by a specific UID, for example 1001:

Terminal
sudo find / -uid 1001

You can then decide to delete , reassign, or archive these files.

Verifying the User Was Deleted

To confirm the user account no longer exists:

Terminal
id username
output
id: 'username': no such user

You can also check:

Terminal
getent passwd username

No output means the user does not exist.

deluser on Debian and Ubuntu

On Debian-based distributions (Debian, Ubuntu, Linux Mint), the deluser command is a higher-level wrapper around userdel. It reads its configuration from /etc/deluser.conf and handles additional cleanup.

To delete a user and their home directory with deluser:

Terminal
sudo deluser --remove-home username

To remove the user from a specific group without deleting the account:

Terminal
sudo deluser username groupname

Troubleshooting

userdel: user username is currently used by process
The user still has running processes. Check them with:

Terminal
ps -u username

Stop the processes normally if possible. If they must be stopped immediately, use:

Terminal
sudo killall -u username

Then run userdel again.

userdel: user username is currently logged in
The user has an active login session. Ask the user to log out, terminate the session, or use userdel -f only when you understand the risk:

Terminal
sudo userdel -f username

userdel: user username does not exist
The account name is wrong or the user was already removed. Check the account database:

Terminal
getent passwd username

If the command prints no output, the user does not exist.

The home directory was not removed
userdel username removes only the account. Use -r when you want to remove the home directory and mail spool:

Terminal
sudo userdel -r username

If the account was already removed, you can manually review and delete the old home directory after confirming it is no longer needed.

Files are still owned by the deleted user
Files outside the home directory are not removed by userdel -r. Find files without a valid owner:

Terminal
sudo find / -nouser

Review the results and decide whether to delete, archive, or reassign those files.

FAQ

Does userdel delete the home directory?
Not by default. Use userdel -r to remove the home directory and mail spool along with the account.

What happens to files owned by a deleted user?
Files outside the home directory remain on the system, owned by the user’s old numeric UID. Use find / -nouser to locate them.

What is the difference between userdel and deluser?
userdel is the low-level command available on all Linux distributions. deluser is a higher-level wrapper available on Debian-based systems that reads configuration from /etc/deluser.conf and provides additional options.

Can I delete a user that is currently logged in?
Not without the -f flag. Either log the user out and kill their processes first, or use userdel -f to force the removal.

Does deleting a user remove their cron jobs?
No. Run sudo crontab -r -u username before deleting the user to remove their scheduled cron jobs.

How do I undo a user deletion?
You cannot undo userdel. If you deleted the home directory with -r, the data is gone unless you have a backup. You would need to recreate the user and restore their files.

Conclusion

The userdel command removes user accounts from Linux. Use -r when you also want to remove the home directory, check active processes before deleting logged-in users, and run find / -nouser afterward to locate files left behind.

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page