Skip to content

How to Delete a User in Linux (userdel and deluser)

Updated 6 min read

Updated: 12 October 2026 · Applies to: Debian 13 (shadow 4.17.4, adduser 3.152), Ubuntu 24.04 (adduser 3.137) and 26.04 (adduser 3.153), AlmaLinux 10 (shadow-utils 4.15) and Rocky Linux 9 (shadow-utils 4.9), tested

To delete a user in Linux together with their home folder and mail spool, run sudo userdel -r username. It works the same on Debian, Ubuntu, AlmaLinux, Rocky Linux and RHEL. On Debian and Ubuntu you can also use sudo deluser --remove-home username, which removes the user's cron jobs as well. Stop the user's processes first, or userdel refuses to run.

sudo pkill -KILL -u alice      # stop everything alice is running
sudo crontab -r -u alice       # remove alice's cron jobs
sudo userdel -r alice          # delete the user, home folder and mail spool

The output below is a lab example from test containers. Replace alice with the user name you want to remove.

1. Check the account and keep a backup

$ id alice
uid=1000(alice) gid=1000(alice) groups=1000(alice)
$ ps -u alice -o pid,etime,cmd
    PID     ELAPSED CMD
    457       00:01 sleep 3000
$ sudo crontab -l -u alice
0 3 * * * /home/alice/backup.sh

Deleting a home folder cannot be undone, so copy anything you may need first, for example sudo tar czf /root/alice-home.tar.gz /home/alice. To see all accounts on the server, see How to List Users using Linux Command Line?

2. Stop the user's processes

If the user still has a process running, userdel stops with exit code 8 and deletes nothing:

$ sudo userdel -r alice
userdel: user alice is currently used by process 457

Stop their processes, then check that nothing is left (ps prints nothing):

sudo pkill -KILL -u alice
ps -u alice -o pid=

userdel -f removes the account even while the user is logged in, but it does not stop their programs, which then run under a UID without a name. Stopping them first is cleaner.

3. Delete the user with userdel (all distributions)

$ sudo userdel -r alice
userdel: alice mail spool (/var/mail/alice) not found
$ id alice
id: 'alice': no such user

The mail spool not found line on Debian and Ubuntu is only a notice: those systems do not create a mail spool for new users, and userdel still deleted the user and /home/alice. userdel also removed the user's personal group (alice).

Without -r, only the account is removed and the home folder stays, now owned by a bare number:

$ sudo userdel bob
$ ls -ld /home/bob
drwx------ 2 1000 1000 4096 Oct 11 17:36 /home/bob

4. Remove a user on Debian and Ubuntu with deluser

deluser is a friendlier front end from the adduser package. With --remove-home it also removes the user's crontab, which userdel leaves behind. Debian 13 prints nothing on success unless you add --verbose:

$ sudo deluser --verbose --remove-home judy
info: Looking for files to backup/remove ...
info: Removing files ...
info: Removing crontab ...
info: Removing user `judy' ...

Ubuntu 24.04 prints the same info: lines without --verbose. Other useful options:

  • sudo deluser --backup --backup-to /root --remove-home erin: saves the user's files to /root/erin.tar.gz before deleting them.
  • sudo deluser --remove-all-files erin: deletes every file the user owns anywhere on the system, not only in the home folder.
  • sudo deluser fred: removes the account but keeps /home/fred.
  • sudo deluser alice sudo: does not delete the user, only removes them from the group sudo. More in How to Add or Remove a User from a Group in Linux?

On a minimal Debian 13 system without Perl, the options that remove files fail:

fatal: In order to use the --remove-home, --remove-all-files, and --backup features, you need to install the `perl' package. To accomplish that, run apt-get install perl.

Install it with sudo apt install perl, or use userdel -r, which does not need Perl.

5. Delete a user on RHEL, AlmaLinux and Rocky Linux

There is no deluser on the RHEL family, so use userdel:

sudo pkill -KILL -u alice
sudo crontab -r -u alice
sudo userdel -r alice

Here useradd creates a mail spool in /var/spool/mail, and userdel -r removed it together with the home folder without printing anything. On AlmaLinux 10, crontab -r keeps a copy and says so: Backup of alice's previous crontab saved to /root/.cache/crontab/crontab.alice.bak. If you mapped the user to an SELinux user, add -Z to remove that mapping too.

6. Clean up what userdel leaves behind

userdel -r only removes the home folder and the mail spool. In our tests it left two things on every distribution:

  • The crontab. It stayed in /var/spool/cron/crontabs/ (Debian and Ubuntu) or /var/spool/cron/ (RHEL family). On AlmaLinux 10 we then created a new user with the same name, and crontab -l -u alice showed the old job again. Run crontab -r -u alice before userdel, or delete the leftover file.
  • Files outside the home folder. Find them with:
    $ sudo find / -xdev -nouser 2>/dev/null
    /srv/shared/report.csv
    /var/spool/cron/crontabs/alice
    Delete them or give them to another user with chown. Do it soon: Linux reuses free UIDs. On Debian, a user we created afterwards received alice's old UID 1000, and ls -l then showed alice's report.csv and crontab as owned by that new user. -xdev keeps find on one file system, so repeat it for other mounted disks. On the RHEL family the crontab file is owned by root, so find -nouser does not show it.

Also remove any rule for the user from /etc/sudoers.d/ and any jobs in /etc/cron.d/; How to List All Cron Jobs for All Users in Linux (crontab, cron.d and systemd Timers) helps you find them.

Lock the account instead of deleting it

If you may need the account or its files later, lock it. -L locks the password and -e 1 sets the account expiry to 2 January 1970; the usermod manual says to set the expiry as well if you want to lock the account and not only password logins:

$ sudo usermod -L -e 1 gina
$ sudo passwd -S gina
gina L 2026-10-11 0 99999 7 -1
$ sudo chage -l gina | grep "Account expires"
Account expires						: Jan 02, 1970

On Rocky Linux 9, passwd -S shows gina LK ... (Password locked.). A password login then failed with su: Authentication failure. Undo it with sudo usermod -U -e '' gina. More ways are in How to Block or Disable Normal User Logins in Linux?

cPanel servers

Never delete a cPanel account's Linux user with userdel or deluser. Use WHM » Account Functions » Terminate Accounts. According to cPanel, termination permanently deletes the account's data and cannot be undone, and you can choose to keep the domain's DNS zone.

Official documentation: cPanel: Terminate Accounts

Related services

KVM VPS hosting

NVMe SSD and full root access, with Free Basic Managed Support.

Unmanaged dedicated servers

full root access and free IPMI KVM, with Free Basic Managed Support.

Linux server management

hardening, patching, monitoring and automation for Ubuntu, Debian, RHEL and AlmaLinux.

Was this answer helpful?

Still stuck? Open a ticket