How to use the deluser command on Ubuntu Linux with examples

|

|

The ‘deluser’ command in Ubuntu Linux allows system administrators to delete or remove user accounts. It retains home directories and mail spools by default, but different switches or flags modify the command’s behavior. For instance, using ‘-f’ or ‘–force’ forces file removal, ‘-r’ or ‘–remove’ eliminates the home directory and mail spool, while ‘–root CHROOT_DIR’…

The deluser command is used on Ubuntu Linux to delete or remove user accounts from the system. This command is particularly useful for system administrators who manage user accounts on Linux systems.

Using the deluser command, you can delete user accounts and their associated files or directories. By default, the deluser command removes user accounts without deleting their home directories and mail spools.

It is a powerful command that can help you manage your Ubuntu Linux system more efficiently.

When you’re ready to learn how to use the deluser commands, follow the guide below:

About the deluser command:

The deluser command is used by system administrators to delete or remove user accounts from Linux systems, including Ubuntu. A friendly and alternative command is userdel.

Like using your mouse and keyboard to delete accounts in the GUI., the deluser is the way to do it on the command line.

By default, the deluser command deletes or removes users without deleting or removing their home directories and mail spools.

Syntax:

The syntax is the rule and format of how the deluser command can be used. The syntax options can be reordered. But a straight format must be followed.,.

Below is an example syntax of how to use the deluser command.

userdel [options] LOGIN.

Options:

The command line options are switches or flags that determine how the commands are executed or controlled. They modify the behavior of the command. They are separated by spaces and followed after the command’s options.

Below are some options for the deluser command:

 LOGIN.Replace LOGIN .. with the name of the account you want to delete. If the account doesn’t exist, the command will fail and not execute.
-f, –force
Use the -f or –force option to force the removal of the user’s files.
-r, –removeUse the -r or –remove option to remove the home directory and mail spool.
-R, –root CHROOT_DIRUse the -R or –root CHROOT_DIR option to specify the directory to chroot into
 -Z, –selinux-userUse the -g or –gid GROUP option to remove any SELinux user mapping for the user

Examples:

Below are some examples of how to run and use the deluser on Ubuntu Linux.

If you want to delete an account named John, run the commands below.

deluser john

Run the commands below if you wish to delete or remove John’s account, including deleting his home directory.

deluser --remove-home john

If you’re not logged in as a root account, you may have to use the sudo command.

sudo deluser --remove-home john

If you want to delete John’s account even while he’s logged in, run the commands below.

sudo deluser --force john

Run the commands below to delete John’s account and back up his home directory.

sudo deluser --backup-to /backup_directory john

The commands above will delete the user account and create an archive of the user’s home directory into the specified path.

When you run deluser with the –help option, you’ll see the help text below:

Usage: userdel [options] LOGIN

Options:
  -f, --force                   force removal of files,
                                even if not owned by user
  -h, --help                    display this help message and exit
  -r, --remove                  remove home directory and mail spool
  -R, --root CHROOT_DIR         directory to chroot into
  -Z, --selinux-user            remove any SELinux user mapping for the user

That’s it!

I hope you like it, and please come back soon for more Ubuntu Linux commands!

You may also like the commands below:

Like this:



One response to “How to use the deluser command on Ubuntu Linux with examples”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.