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] user
deluser --system [options] user
deluser --group groupname

PARAMETERS

user
    The username of the account to be deleted.

--remove-home
    Remove the user's home directory and mail spool. This is often the default behavior depending on configuration in /etc/deluser.conf.

--remove-all-files
    Remove all files owned by the user on the system. Use with extreme caution as this is a very powerful and potentially destructive option.

--backup
    Create a compressed archive (.tar.bz2) of the user's home directory before deletion. The archive is usually saved in the current working directory.

--backup-to DIR
    Specify a directory where the backup archive should be saved. Requires --backup.

--system
    Delete a system user account. By default, deluser only deletes normal (non-system) user accounts.

--force
    Force deletion, ignoring some errors, such as issues with deleting files.

--group groupname
    Delete a group. This option is typically used when the command is invoked as delgroup, which is often a symlink to deluser.

-h, --help
    Display a help message and exit.

DESCRIPTION

deluser is a command-line utility used to remove user accounts from a Linux system. It provides a higher-level, more user-friendly interface for user deletion compared to the lower-level userdel command, especially on Debian-based distributions (like Ubuntu).

While userdel focuses solely on removing the user account and password entry, deluser is a Perl script that can handle additional tasks such as automatically removing the user's home directory, mail spool, and entries from system groups, or backing up user data, all configurable via simpler options and system defaults in /etc/deluser.conf. It ensures a cleaner and more comprehensive removal of user data and system references.

CAVEATS

deluser vs. userdel: deluser is a Perl script primarily for Debian-based systems, offering more comprehensive removal features and better default behavior via /etc/deluser.conf. userdel is a lower-level binary found on most Linux systems.

Root Privileges: deluser requires root privileges (or sudo) to execute.

--remove-all-files: This option is extremely powerful and dangerous; it will remove *all* files on the system owned by the specified user, regardless of their location. Use it with utmost care and only when absolutely necessary.

CONFIGURATION FILE

deluser reads its default behavior and settings from the configuration file /etc/deluser.conf. Administrators can modify this file to define policies for home directory removal, backup procedures, group handling, and other options.

GROUP MEMBERSHIP

By default, deluser automatically removes the specified user from all system groups they were a member of. If the user was the sole member of a private group (a group created specifically for that user), deluser may also delete that group, depending on the configuration.

HISTORY

deluser is part of the debianutils package, developed specifically for Debian-based distributions. It emerged as a more robust and user-friendly alternative to the standard userdel utility, providing administrators with a higher-level abstraction for user management. Its design allows for configurable default behaviors and more thorough clean-up of user-associated resources.

SEE ALSO

adduser(8), userdel(8), passwd(1), groupadd(8), groupdel(8)

Copied to clipboard