Linux How to use userdel to delete users

  

As a Linux system administrator, you need to manage the system user accounts regularly, and delete unnecessary users in time to avoid unnecessary trouble. To delete user accounts, you need to use the userdel command. Xiaobian will introduce you to Linux using the userdel command to delete users.

userdel what

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 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 privileges can perform this operation & rdquo; or similar information. After we get the privilege, we can remove the user from your console by typing userdel. Below is an example of using userdel by default.

$ sudo userdel pasadena

or

# userdel pasadena

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

Completely delete user home directory

Without user option, only user will be deleted. The user's home directory will still be in the /home directory.

As we enter the /home directory, we can still see ID 1002 has pasadena folder. A created user will usually have a group name that is the same as the username. 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 users, we can use the -r option. This option will also delete the user's mail pool, if it exists.

forcibly remove a user

userdel provides -f option to force the removal of the user. This option still works even when the user has logged into the Linux system. Take a look at the sample screenshot. The above

pasadena screenshot displays the user has logged into the system. The process 6218 it is tagged is the SSHD process. And when we use “userdel -f pasadena”, only the user information that has been logged in to be deleted will be displayed. The command itself has been successful. If we use the cat command to view the contents of /etc/passwd, we can't see the user pasadena. His home directory still exists but the owner can only display it as a numeric ID.

One thing we must understand is that the userdel with the -f option does not disconnect the existing SSH link for that user. Therefore, even if the user does not already exist, it is actually a login state and is an active user. However, you cannot log in again after the user logs out because the user has been deleted.

So this option is dangerous to use because it puts your system into an inconsistent state.

Summary

The above is a description of how Linux uses the userdel command to delete a user account. The userdel command can be used not only to delete system user accounts, but also to delete files.

Copyright © Windows knowledge All Rights Reserved