On Linux operating systems, the deluser and delgroup commands remove a user or group from the system.

Description

deluser and delgroup remove users and groups from the system according to command line options and configuration information in /etc/deluser.conf and /etc/adduser.conf. They are friendlier front ends to the userdel and groupdel programs, removing the home directory as option or even all files on the system owned by the user to be removed, running a custom script, and other features. deluser and delgroup can run in one of three modes:

  • Description
  • Syntax
  • Configuration
  • Return values
  • Files
  • Examples
  • Related commands
  • Linux commands help

To remove a normal user

If called with one non-option argument and without the –group option, deluser removes a normal user.

By default, deluser removes the user without removing the home directory, the mail spool or any other files on the system owned by the user. Removing the home directory and mail spool can be achieved using the –remove-home option.

The –remove-all-files option removes all files on the system owned by the user. Note that if you activate both options –remove-home has no effect because all files including the home directory and mail spool are already covered by the –remove-all-files option.

If you want to backup all files before deleting them, you can activate the –backup option to create a file username.tar(.gz|.bz2) in the directory specified by the –backup-to option (defaulting to the current working directory). Both the remove and backup options can also be activated for default in the configuration file /etc/deluser.conf. See deluser.conf for details.

If you want to remove the root account (uid 0), then use the –force parameter; this prevents removing the root user by accident.

If the file /usr/local/sbin/deluser.local exists, it will be executed after the user account is removed to do any local cleanup. The arguments passed to deluser.local are: “username uid gid home-directory”.

To remove a group

If deluser is called with the –group option, or delgroup is called, a group will be removed.

Warning: The primary group of an existing user cannot be removed.

If the option –only-if-empty is given, the group won’t be removed if it has any members left.

To remove a user from a specific group

If called with two non-option arguments, deluser removes a user from a specific group.

Syntax

deluser [–quiet] [–system] [–help] [–version] [–conf FILE] [–force] [–remove-home] [–remove-all-files] [–backup] [–backup-to DIR] user

deluser –group [–quiet] [–system] [–help] [–version] [–conf FILE] group

delgroup [options] [–quiet] [–system] [–help] [–version] [–conf FILE] group

deluser [options] user group

Options

Configuration

The file /etc/deluser.conf contains defaults for the programs deluser and delgroup. Each option takes the form “option = value”. Double or single quotes are allowed around the value. Comment lines must have a hash sign ("#") at the beginning of the line.

deluser and delgroup also read /etc/adduser.conf, see adduser.conf; settings in deluser.conf may overwrite settings made in adduser.conf.

The valid configuration options are:

Return values

Files

Examples

deluser myuser

Deletes the user account myuser.

deluser –remove-home myuser

Deletes the user account myuser, and removes that user’s home directory as well.

deluser –force myuser

Deletes the user account myuser even if that user is currently logged in.

deluser –backup-to /directory myuser

Deletes the user account myuser and backs up their files in a tar archive called myuser.tar, which is created in the directory /directory.

delgroup mygroup

Deletes the group mygroup.

adduser — Add a user to the system.addgroup — Add a group to the system.groupadd — Add a group to the system.useradd — Add a user to the system.