Someone has left, and their account has to go without taking their files with it. This guide uses deluser to remove a Linux user, group or membership, keeping the default operation narrow and making a deliberate backup before anything is deleted. The examples match adduser 3.137ubuntu1, the installed version on this machine.
Allow about fifteen minutes for a simple account removal, or longer if you need to audit files and test a backup.
sudo invocation.Warning: these commands change system account data. The file-removal variants are destructive, so read the full command before running it.
Start with read-only checks. delgroup is an alias that selects group-removal mode; deluser --group selects the same mode explicitly.
$ command -v deluser delgroup
/usr/sbin/deluser
/usr/sbin/delgroup
$ dpkg-query -W -f='${Package} ${Version}\n' adduser
adduser 3.137ubuntu1
$ deluser --version
deluser version 3.137ubuntu1
With one ordinary username, deluser removes the account but does not remove its home directory, mail spool or other files owned by that user. That is the safer default. It will not remove the root account.
Checkpoint: inspect the target before continuing.
$ getent passwd ACCOUNT_NAME
$ id ACCOUNT_NAME
$ getent group ACCOUNT_NAME
Replace ACCOUNT_NAME with the real name. If the first command returns nothing, stop and check the spelling rather than switching to a more destructive option.
Use this form when you want to remove the login but retain the home directory for review or handover:
$ sudo deluser ACCOUNT_NAME
$ printf 'exit status: %s\n' "$?"
exit status: 0
A zero status means this invocation completed successfully. Verify both the account database and the retained files:
$ getent passwd ACCOUNT_NAME
$ sudo test -d /home/ACCOUNT_NAME && echo 'home directory retained'
Checkpoint: the account lookup should produce no line. Keeping the home directory does not bring the account back: it holds data, not the removed account's password and account record. Preserve it until its owner or an administrator has reviewed it.
If the home directory and mail spool should go, make a backup first. Create a private destination and check its ownership. The destination must exist before the removal command runs:
$ sudo install -d -m 700 -o root -g root /var/backups/deluser
$ sudo deluser --backup-to /var/backups/deluser --remove-home ACCOUNT_NAME
$ sudo find /var/backups/deluser -maxdepth 1 -type f -printf '%f\n'
--backup-to also enables --backup. You do not need both..gz. Use --backup-suffix .xz only when the installed tar supports that compression.$ sudo tar -tzf /var/backups/deluser/ACCOUNT_NAME.tar.gz | sed -n '1,20p'
$ getent passwd ACCOUNT_NAME
$ sudo test ! -d /home/ACCOUNT_NAME && echo 'home directory removed'
Archive names and contents depend on the account and configuration. Keep the archive until the data has been restored or formally disposed of.
Recovery: recreating a user does not automatically restore ownership, credentials or service configuration. To recover files, create or select the intended account first, extract into a staging directory, inspect paths and ownership, then copy the required files with an explicit plan.
--remove-all-files searches for all files owned by the user on the system. It includes the home directory and mail spool, so adding --remove-home does not add anything. This can affect application data outside /home, and the search is constrained by the regular expressions in NO_DEL_PATHS and filesystem exclusions.
Destructive action: do not use it as a quicker version of ordinary account removal. First list likely files and understand the service impact.
$ sudo find / -xdev -user ACCOUNT_NAME -print 2>/dev/null | sed -n '1,100p'
$ sudo deluser --backup-to /var/backups/deluser --remove-all-files ACCOUNT_NAME
The first command is only an audit and its output is limited here for readability. The second is irreversible for files not present in the backup. Run it only after checking the complete inventory, stopping dependent services and confirming the backup archive.
For an empty group, use --only-if-empty as a guard:
$ getent group GROUP_NAME
$ sudo delgroup --only-if-empty GROUP_NAME
$ getent group GROUP_NAME
The group is not removed when members remain. The primary group of an existing user cannot be removed. If you need to remove one user from a supplementary group, use two arguments:
$ sudo deluser ACCOUNT_NAME GROUP_NAME
$ id ACCOUNT_NAME
Check the resulting group list in id. This changes membership, not the user account and not files already owned by that group.
Add --system when the operation must apply only to a system user or group. If the named system account does not exist, the command treats that as a successful no-op. That is useful in package maintainer scripts, but it can hide a spelling error in an interactive session:
$ sudo deluser --system SERVICE_ACCOUNT
$ printf 'exit status: %s\n' "$?"
Configuration facts:
/etc/deluser.conf and also /etc/adduser.conf. Settings in deluser.conf can override settings from the latter.REMOVE_HOME = 0 and BACKUP_TO = ".". Comments require # in the first column.Security warning: do not grant partial sudo access to deluser with a restricted argument pattern. The manual warns that this can be bypassed and may allow arbitrary account creation. If delegated removal is needed, use a reviewed wrapper with a fixed allow-list and a separate audit trail.
deluser ACCOUNT_NAME when files should remain.--only-if-empty for group removal./etc/deluser.conf and avoided unsafe partial privilege delegation.