Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the userdel command to delete a user in Linux

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

How do I use the userdel command to delete a user in Linux? In view of this problem, this article introduces the corresponding analysis and answers in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.

What is serdel?

Userdel is an underlying tool for deleting users. On Debian, we usually use the deluser command. Userdel queries the system account files, such as / etc/password and / etc/group. Then it deletes all entries related to the user name. The user name must exist before we delete it.

How to use userdel

Since userdel modifies the system account file, we need root privileges to run it. Otherwise we will encounter an error message "only root permissions can perform this operation" or something like that. After we get the privilege, we can delete the user from your console by typing userdel. Here is an example of using 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 that the user has successfully deleted it.

Completely delete the user's home directory

Using userdel without an option only deletes the user. The user's home directory will still be in the / home directory.

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

In order to completely delete the home directory when deleting the user, we can use the-r option. This option also deletes the user's mail pool, if it exists.

Force deletion of a user

Userdel provides the-f option to force the user to be deleted. This option remains in effect even when the user has logged in to the Linux system. Please take a look at the sample screenshot.

The screenshot above shows that the user pasadena has logged in to the system. 6218 of the process it is marked with is a SSHD process. When we use "userdel-f pasadena", we will only display the information of the users who are logged in and will be deleted. The command itself has been successful. If we use the cat command to view the contents of / etc/passwd, we don't see the existence of the user pasadena. His home directory still exists, but the owner can only be displayed as the number ID.

One thing we must understand is that userdel with the-f option does not break the user's existing SSH link. Therefore, even if the user no longer exists, it is actually logged in and is an active user. However, you can no longer log in after the user logs out, because the user has been deleted.

So this option is a bit dangerous to use because it will put your system into an inconsistent state.

This is the answer to the question about how to use the userdel command to delete users in Linux. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report