Linux is a multi-user operating system in which we can create and remove users. In this article, we are going to discuss userdel command in Linux, which is used to remove a user account and its associated records. We will also discuss its options and examples.
What is userdel command?
In a Linux system, the userdel command is used to remove a user account and its associated files. Basically, this command alters the system account files by erasing any entries that relate to the given user. It's a low-level command for deleting users and their records.
Options with the command
This is used to simply delete the user and its records with a given username. When a user account is deleted using userdel on most Linux operating systems, the user home, and mail spool folders are not deleted.
This option causes the given user account to be removed. It makes no difference if the user is still logged in. It also causes userdel to delete the user's home directory and mail spool, even if the home directory is shared by another user or the mail spool is not owned by the selected user.
When we use this option to delete a user, the files in the user's home directory, as well as the home directory itself and the user's mail spool, are deleted. All files in other file systems will have to be individually looked for and removed.
Changes should be made in the CHROOT_DIR chroot directory, and configuration files should be used from the same location.
For the user's login, removes any Security-Enhanced Linux user mapping.
This option displays a help message and then exits the programme.
Exit status of userdel
userdel exits with one of the following exit codes, depending on what occurred:
When the command is executed successfully success
When the command cannot update the passwd file.
When the syntax is wrong.
When the given user doesn't exist.
When the command cannot delete the user because the given user is currently logged in.
When the command cannot update the group file.
When the command cannot remove the home directory.
In this article, we discussed userdel command and its options which perform several functions, including deleting a user and the files in the user's home directory and mail spool, removing any Security-Enhanced Linux user mapping for the user's login, displaying help message, etc.
People are also reading: