In Linux, managing the users is one of the crucial activities performed by an administrator. While working in a network, multiple users have access to their concerned data. Adding or removing users is a frequently performed activity while managing users. In this post, we will list the possible methods to remove users on Linux Mint 21 (the current latest LTS of Linux Mint).
How to Remove Users on Linux Mint 21 Using CLI?Linux Mint is one of the leading distributions of Debian, which offers strong support to manage the system through commands. The “userdel” and the “deluser” commands are used to remove a user on Linux Mint. This section will show the practical demonstration of both methods.
Remove Users Using the “userdel” CommandBefore getting into the detailed working, the syntax of the “userdel” command is explained below.
Syntax:The “userdel” command removes the user from the system by following the syntax below.
If you want to delete the user alongside its home directory, use the syntax below.
$ userdel <username>
$ userdel r <username>
Working:What does the “userdel” command do? Let’s look at the following operations, which are carried out using the “userdel” command.
- The user’s information is stored in the user files, i.e., “/etc/passwd” and “/etc/shadow”.
- The information carried by the group files of a user, i.e., “/etc/group” and “/etc/gshadow”.
Example: Remove the User OnlyThe command below will remove the user named genieuser with its files and the groups to which the user belongs.
$ sudo userdel genieuser
Example: Remove Users With Home DirectoryIf you want to remove the user alongside its home directory, then use the “r” flag with its name, as the command below will remove the home directory and the mail spool of the user named genieeditor.
Note: The above command will only remove the home directory if the mail spool is not found.
$ sudo userdel -r genieeditor
Remove Users Using the “deluser” CommandThe “deluser” also removes the user like “userdel”. However, they differ, which will be discussed in this section. Let’s have a look at the general syntax of the deluser command. Syntax:
While both commands have the same purpose, the deluser command has the more enriched and detailed support of the options described below.
$ deluser <username>
- –remove-home: Deletes the home directory.
- –backup: Create a backup before deletion.
- –remove-all-files: It will delete all files owned by the user.
- –system: Deletes only the system user (if this option is used with the normal user, then the command will be unable to delete the user).
- –backup-to [directory]: Creates a backup to a specific directory before deleting the user.
Example: Remove the UserThe below command will delete the user named “linuxuser” from the system.
$ sudo deluser linuxuser
Example: Create a Backup and Then Remove UsersWhile deleting a user may cause unintended results, creating a backup before deleting is recommended. We have used the command provided below, which will create the backup, and then it will delete the user.
$ sudo deluser --backup genieuser