deluser

user managementlinux
The deluser command is one of the most frequently used commands in Linux/Unix-like operating systems. deluser The deluser command is used to remove users from the system. It is a friendlier frontend to the userdel command, providing additional options to manage user removal, including handling of the user's home directory and mail spool.

Quick Reference

Command Name:

deluser

Category:

user management

Platform:

linux

Basic Usage:

deluser username

Common Use Cases

  • 1

    User management

    Remove user accounts from the system safely

  • 2

    Security maintenance

    Remove unused or compromised accounts to maintain system security

  • 3

    Home directory cleanup

    Optionally remove user home directories and mail spools

  • 4

    Group removal

    Remove user groups along with user accounts

Syntax

deluser [options] user
deluser --group [options] group

Options

Option Description
--backup Backup all files in the user's home directory before removing
--backup-to DIR Target directory for backups (default: current directory)
--backup-suffix SUFFIX Suffix for backup file (default: ~)
--force Force removal, even if the user is still logged in
--group Remove a group instead of a user
--only-if-empty Only remove a group if it has no members
--quiet Suppress informational messages, only report errors
--remove-all-files Remove all files owned by the user
--remove-home Remove the user's home directory
--system Only remove if system user/group
--help Display help information and exit
--version Output version information and exit

Examples

How to Use These Examples

The examples below show common ways to use the deluser command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

#

Basic Examples:

# Remove a user
sudo deluser john
# Remove a user and their home directory sudo deluser --remove-home john
# Remove a user and all their files (home directory, mail spool, etc.) sudo deluser --remove-all-files john
# Remove a user from a specific group (but keep the user) sudo deluser john developers
# Remove a group (not a user) sudo deluser --group developers
# Backup user's files before removing them sudo deluser --backup --remove-home john

Advanced Examples:

# Remove a user with custom backup directory
sudo deluser --backup --backup-to /mnt/backups --remove-home john

# Remove a user and generate a backup with timestamp
sudo deluser --backup --backup-suffix $(date +%Y%m%d) --remove-home john

# Remove a system user
sudo deluser --system john

# Remove a user forcefully, even if the user is still logged in
sudo deluser --force john

# Remove a group and its configuration files
sudo deluser --group --only-if-empty developers

Try It Yourself

Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

Understanding Syntax

Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

Notes

Important Considerations:

  • Root privileges: Removing users requires administrative privileges (sudo or root)
  • User sessions: It's recommended to ensure the user is not logged in before removing
  • Data loss: The --remove-home and --remove-all-files options permanently delete data
  • System users: Be careful when removing system users as this may break system services
  • Primary group: By default, a user's primary group is not removed with the user

Backing Up User Data:

When using the backup options:

  • The --backup option creates a tarball of the user's home directory
  • Default backup location is the current directory unless specified with --backup-to
  • The backup filename format is: username-backup-YYYY-MM-DD.tar.gz
  • You can add a custom suffix to the backup with --backup-suffix

User vs. Group Removal:

  • Without the --group option, deluser removes a user account
  • With the --group option, deluser removes a group
  • To remove a user from a group (but keep the user), specify both the user and group names
  • The --only-if-empty option ensures groups with members are not accidentally removed

System Configuration:

deluser behavior can be customized through configuration files:

  • /etc/deluser.conf - Main configuration file
  • /etc/adduser.conf - Shared configuration with adduser command

Related Commands:

  • userdel - Low-level command that deluser uses internally
  • adduser - Companion command for adding users
  • groupdel - Low-level command for removing groups
  • usermod - Modify user accounts

Differences Between Distributions:

The deluser command may have different options or behavior on different Linux distributions:

  • Debian/Ubuntu provides the most feature-rich version described here
  • Some distributions may not include deluser, offering only userdel
  • Always check the man pages for your specific distribution

Tips & Tricks

1

Use the --remove-home option to remove the user's home directory

2

Use the --remove-all-files option to remove all files owned by the user

3

Use the --backup option to create a backup of the user's home directory

4

Use the --force option to force the removal of the user

5

Use the --system option to remove a system user

Common Use Cases

User management

Remove user accounts from the system safely

Security maintenance

Remove unused or compromised accounts to maintain system security

Home directory cleanup

Optionally remove user home directories and mail spools

Group removal

Remove user groups along with user accounts

System administration

Manage system accounts as part of routine maintenance

Related Commands

These commands are frequently used alongside deluser or serve similar purposes:

Use Cases

1

User management

Remove user accounts from the system safely

2

Security maintenance

Remove unused or compromised accounts to maintain system security

3

Home directory cleanup

Optionally remove user home directories and mail spools

4

Group removal

Remove user groups along with user accounts

5

System administration

Manage system accounts as part of routine maintenance

Learn By Doing

The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the deluser command works in different scenarios.

$ deluser
View All Commands