Userdel command-delete user account from Linux

Source: Internet
Author: User

To maintain a user on a server, add, modify, and delete users. When a user no longer needs to log on to the system for some reason, we need to delete the user to avoid security vulnerabilities. In Linux, we use the userdel command to delete a user.

What is userdel?

Userdel is a tool used to delete users at the underlying layer. In Debian, we usually use the deluser command. Userdel queries account files, such as/etc/password and/etc/group. It deletes all user name-related entries. The user name must exist before we delete it.

How to Use userdel

Because userdel modifies the system account file, we need the root privilege to run it. Otherwise, we will encounter an error message"This operation can be performed only with the root permission.Or similar information. After we get the privileges, We can enter userdel to delete users from your console. The following 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 the root permission. When we have the permission, the system will not give an error message, which means that the user has been deleted successfully.

Completely Delete the user's home directory

If userdel is used without the option, only the user is deleted. 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. A created user usually has the same group name as the user name. 1002 is the UID of the pasadena user name and the GID of the pasadena group name.

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

Force delete a user

Userdel provides the-f option to force users to be deleted. This option takes effect even if you have logged on to Linux. Take a look at the example.

The above shows that pasadena has logged on to the system. The marked process 6218 is an SSHD process. When "userdel-f pasadena" is used, only the logged-on user information to be deleted is displayed. The command itself is successful. If we use the cat command to view the/etc/passwd content, we cannot see that the user pasadena exists. The Home Directory still exists, but the owner can only display it as a numerical ID.

One thing we must understand is that userdel with the-f option will not disconnect the user's existing SSH link. Therefore, even if the user does not exist, the user is still logged on and active. However, you cannot log on again after logging out because the user has been deleted.

Therefore, this option may be dangerous because it will bring your system into an inconsistent state.

Summary

Userdel is a tool used to delete users in Linux. Userdel is also the backend of the deluser command, which is a script for Deleting Users written in perl. As usual, you can enter man userdel to view more details about the userdel command.

How to delete users and groups using userdel in Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.