LinuxCommandLibrary

deluser

Remove user accounts

TLDR

Remove a user

$ sudo deluser [username]
copy

Remove a user and their home directory
$ sudo deluser --remove-home [username]
copy

Remove a user and their home, but backup their files into a .tar.gz file in the specified directory
$ sudo deluser --backup-to [path/to/backup_directory] --remove-home [username]
copy

Remove a user, and all files owned by them
$ sudo deluser --remove-all-files [username]
copy

SYNOPSIS

deluser [options] login
deluser --group [options] groupname
deluser [options] login group

PARAMETERS

--help
    Display help message and exit

--quiet
    Suppress informational output

--remove-home
    Remove user's home directory and mail spool

--remove-all-files
    Remove all files owned by user on the system

--backup
    Create backup of home directory before removal

--backup-to


    Backup home directory to specified directory

--force-badname
    Allow usernames with invalid characters

--allow-badname
    Deprecated alias for --force-badname

--group
    Treat argument as groupname to delete

--group-overwrite
    Overwrite user's secondary group memberships

--system
    Only delete if user is marked as system account

--conf
    Use specified config file

DESCRIPTION

deluser is a user-friendly command-line utility from the Debian adduser package, serving as a safe frontend to the lower-level userdel(8). It removes specified user accounts from the system's user and group databases (/etc/passwd, /etc/shadow, /etc/group), optionally deleting the user's home directory, mail spool, and all files owned by the user. Unlike userdel, deluser performs sanity checks: it refuses to delete users who are currently logged in (unless forced), verifies username validity, and handles backups to prevent data loss.

Primarily used on Debian-based distributions like Ubuntu, it supports both regular and system users. For groups, it integrates with delgroup functionality via options like --group. It automatically removes the user from secondary groups and can overwrite group memberships. The command is a Perl script, making it portable and extensible.

Key advantages include interactive prompts for confirmation (unless --quiet), safe file removal with exclusion lists, and integration with PAM for authentication. It's essential for system administration tasks like cleaning up test accounts or decommissioning services.

CAVEATS

Refuses to delete logged-in users; kill processes first or use --remove-all-files. Does not remove crontabs, at jobs, or print queues automatically. System users may require --system. Backups exclude dotfiles unless specified.

GROUP REMOVAL

To remove a user from a group: deluser login group. To delete a group: deluser --group groupname.

CONFIG FILE

Settings customizable in /etc/deluser.conf, including removal options and exclusions.

HISTORY

Introduced in Debian 1.1 (1996) as part of Ian Jackson's adduser suite, replacing ad-hoc scripts. Evolved through Debian releases with Perl enhancements for safety and PAM support; widely adopted in Ubuntu and derivatives.

SEE ALSO

userdel(8), adduser(8), delgroup(1), groupdel(8), useradd(8)

Copied to clipboard