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

Example of how to check the capacity of MySQL database table

This article introduces the command statements fo...

Analysis of the difference between HTML relative path and absolute path

HTML beginners often encounter the problem of how ...

WEB Chinese Font Application Guide

Using fonts on the Web is both a fundamental skill...

How to insert Emoji expressions into MySQL

Preface Today, when I was designing a feedback fo...

Play and save WeChat public account recording files (convert amr files to mp3)

Table of contents Audio transcoding tools princip...

Vue ElementUI implements asynchronous loading tree

This article example shares the specific code of ...

Introduction to the use of anchors (named anchors) in HTML web pages

The following information is compiled from the Int...

How to retrieve password for mysql 8.0.22 on Mac

Mac latest version of MySQL 8.0.22 password recov...

vue3 custom directive details

Table of contents 1. Registering custom instructi...

What hidden attributes in the form can be submitted with the form

The form elements with visibility=hidden and displ...

Docker deploys net5 program to achieve cross-platform functions

Deployment environment: docker container, liunx s...

Python3.6-MySql insert file path, the solution to lose the backslash

As shown below: As shown above, just replace it. ...

Introduction to new ECMAscript object features

Table of contents 1. Object properties 1.1 Attrib...