How to delete a user account from a Linux system

Source: Internet
Author: User

Maintaining users on the server is adding, modifying, and deleting users. When a user no longer needs to log on to the system for some reason, we need to remove this user to avoid security vulnerabilities. On a Linux system, we use the Userdel command to delete a user. It is recommended to learn Linux video Tutorials .

What is Userdel?

Userdel is an underlying tool for removing users. On Debian, we usually use the Deluser command. Userdel will query system account files, such as/etc/password and/etc/group. Then it will delete all entries associated with the user name. The user name must exist before we delete it.
How to use Userdel

Since Userdel will modify the system account file, we need root privileges to run it. Otherwise we will encounter an error message "Only root permission to perform this operation" or similar information. After we get the privilege, we can remove the user from your console by entering Userdel. Here is a sample that uses Userdel by default.

$ sudo userdel Pasadena

Or

# Userdel Pasadena

As you can see, we cannot delete user Pasadena without root permission. When we have permission, the system does not give an error message, which means the user has successfully deleted it.
Completely delete the user home directory

Using Userdel with no options will only delete the user. The user's home directory will still be in the/House directory.

When we enter the/home directory, we can still see that ID 1002 has the Pasadena folder. A user who has been created will typically have a group name that is the same as the user name. 1002 is the UID of the Pasadena user name and the GID of the Pasadena group name.

We can use the-r option in order to completely delete the home directory when the user is deleted. This option also removes the user's message pool, if one exists.

Force deletion of a user

Userdel provides the-F option to force the deletion of users. This option still takes effect even when the user has logged into the Linux system. Take a look at the example.

The above shows that the user Pasadena has logged into the system. Its marked process 6218 is the SSHD process. And when we use "userdel-f Pasadena" only displays the user information that has been logged in to be deleted. The command itself has succeeded. If we use the Cat command to view the contents of the/etc/passwd, we do not see that the user Pasadena exists. His home directory still exists but the owner can only be displayed as a numeric ID.

One thing we must understand is that userdel with the-f option will not disconnect the SSH link that the user already has. Therefore, even if the user does not already exist, it is in fact still logged in and is an active user. However, when the user logs out, no more logons, because the user has been deleted.

So this option is a bit risky to use because it puts your system into an inconsistent state.
Summarize

Userdel is a tool for removing users inside a Linux system. Userdel is also the back end of the Deluser command, a script that is written in Perl to delete users. As always, you can enter man Userdel to see more details about the Userdel command.

Learn more about the e- mentor network .

How to delete a user account from a Linux system

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.