Deleting a Linux user closes a local login that should no longer be available, but it can also remove the account's home directory and mail spool. A safe deletion starts by confirming the exact account, checking for active work, and deciding what user-owned data must stay before the account record is removed.
Most Linux systems provide userdel from the shadow account-management tools. The --remove option deletes the account and removes its home directory plus local mail spool when they exist, while files owned by the account outside that home directory can remain on disk under the old numeric UID.
A regular local account is the right target here; service accounts and the account currently being used for administration need separate change planning. If access should only be suspended, lock or expire the account instead of deleting it.
Related: How to create a user in Linux
Related: How to lock a user account in Linux
Steps to delete a Linux user with userdel:
- Confirm the exact account record to remove.
$ getent passwd audituser audituser:x:1001:1001:Audit User:/home/audituser:/bin/bash
Replace audituser with the target login. A normal login usually has a home path under /home and a UID in the regular-user range for the distribution.
- Check whether the account still has running processes.
$ ps -u audituser -o pid,tty,stat,cmd PID TT STAT CMDNo rows below the header means the account has no current processes in this check. Sign out or stop active work before deleting the account.
Related: How to show logged-in users in Linux
Related: How to force a user to log out in Linux - Back up any files from the account home directory that must be retained.
Deleting with --remove removes /home/audituser and the mail spool when they exist. Files owned by the user outside the home directory can remain on disk under the old numeric UID.
- Delete the account and remove its home directory.
$ sudo userdel --remove audituser userdel: audituser mail spool (/var/mail/audituser) not found
The mail spool message is expected when the account has no local mail spool. On Debian or Ubuntu, sudo deluser --remove-home audituser is another supported account-removal command.
- Confirm the account no longer resolves.
$ id audituser id: 'audituser': no such user
- Confirm the home directory was removed.
$ ls -ld /home/audituser ls: cannot access '/home/audituser': No such file or directory
If the command shows a remaining directory, review its contents before deleting or reassigning ownership.
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.