Detailed tutorial on how to delete Linux users using userdel command

Detailed tutorial on how to delete Linux users using userdel command

What is serdel

userdel is a low-level tool for deleting users. On Debian, we usually use the deluser command. userdel queries system account files such as /etc/password and /etc/group. Then it will delete all entries related to the username. The username must exist before we can delete it.

How to use userdel

Since userdel modifies system account files, we need root privileges to run it. Otherwise we will encounter an error message "Only root privileges can perform this operation" or similar messages. After we have gained privileges, we can delete the user from your console by typing userdel. Below is an example that uses userdel by default.

$ sudo userdel pasadena

or

# userdel pasadena

As you can see, we cannot delete the user pasadena without root privileges. When we have permission, the system will not give an error message, which means the user has been successfully deleted.

Completely delete the user's home directory

Using userdel without options will only delete the user. The user's home directory will still be in the /home directory.

When we go into the /home directory, we can still see that ID 1002 has the pasadena folder. Created users will usually have a group name that is the same as their username. 1002 is the UID of the pasadena username and the GID of the pasadena group name.

To completely remove the home directory when deleting a user, we can use the -r option. This option will also delete the user's mail pool, if it exists.

Force delete a user

userdel provides the -f option to force deletion of a user. This option works even when the user is logged into the Linux system. Please take a look at the example screenshots.

The screenshot above shows that user pasadena has logged into the system. The process 6218 it is marked as is the SSHD process. When we use "userdel -f pasadena", only the logged-in user information to be deleted will be displayed. The command itself succeeded. If we view the contents of /etc/passwd using the cat command, we cannot see that the user pasadena exists. His home directory still exists but the owner is shown only as a numeric ID.

One thing we must understand is that userdel with -f option will not disconnect the existing SSH connection of the user. Therefore, even though the user no longer exists, they are still logged in and are an active user. However, after the user logs out, he cannot log in again because the user has been deleted.

Therefore this option is somewhat dangerous to use, as it can put your system into an inconsistent state.

Summarize

userdel is a tool for deleting users from within a Linux system. userdel is also the backend for the deluser command, which is a script written in perl to delete users. As usual, you can type man userdel to see more details about the userdel command.

The above is a detailed tutorial on how to use the userdel command to delete Linux users. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

You may also be interested in:
  • Use of Linux date command
  • How to run Linux commands in the background
  • Use of Linux file command
  • Use of Linux telnet command
  • Use of Linux ls command
  • Use of Linux read command
  • Use of Linux usermod command
  • Use of Linux ln command
  • Usage of Linux userdel command

<<:  Summary of Vue's common APIs and advanced APIs

>>:  Detailed explanation and examples of database account password encryption

Recommend

Brief analysis of the introduction and basic usage of Promise

Promise is a new solution for asynchronous progra...

Multiple ways to change the SELECT options in an HTML drop-down box

After the form is submitted, the returned HTML pag...

Analysis of MySQL joint index function and usage examples

This article uses examples to illustrate the func...

How to set up the terminal to run applications after Ubuntu starts

1. Enter start in the menu bar and click startup ...

5 Ways to Clear or Delete Large File Contents in Linux

Sometimes, while working with files in the Linux ...

How to use jsx syntax correctly in vue

Table of contents Preface Virtual DOM What is Vir...

How to optimize MySQL deduplication operation to the extreme

Table of contents 1. Clever use of indexes and va...

Implementing custom radio and check box functions with pure CSS

1. Achieve the effect 2 Knowledge Points 2.1 <...

MySQL case when group by example

A mysql-like php switch case statement. select xx...

React Native environment installation process

react-native installation process 1.npx react-nat...

Implementation of CSS border length control function

In the past, when I needed the border length to b...

Install MySQL in Ubuntu 18.04 (Graphical Tutorial)

Tip: The following operations are all performed u...