How to Lock & Remove user in Linux
In the previous article we are discussed how to add user in Linux with the command “useradd” commands , we are adding users in the home directory of system and after some time of using more irrelevant entries stored in the home directory & we have to remove this user, In this article we are use “userdel” command for removing user in linux.
As a System Administrator in Linux system , you may have to add as well as remove users account at after sometime when a user account may become useless for so long, or user may leave the organization or company or any other reasons we have to remove these users account form our home directory.
When removing user accounts on a Linux system, it is also important to remove their home directory to free up space on the storage devices for new system users or other services.
Deleting / Removing a User Account with Home Directory
- First of all before Removing the user in Linux we are adding user by “useradd” and after that we are removing the user, first we will start by creating two user accounts on my system that is user “shane” and user “rob” with their home directories /home/shane and /home/rob respectively using “useradd” command.
- After adding user , Let’s go to our objective to see how to delete or remove user accounts in Linux using “deluser” (For Debian and it’s derivatives) and “userdel” (For RedHat/CentOS based systems) command.
The directives inside the configuration file for “deluser” and “userdel” commands determine how this it will handle all user files and directory when you run the command.
Let us look at the configuration file for the “deluser” command which is /etc/deluser.conf on Debian derivatives such as Ubuntu, Kali, Mint and for RHEL/CentOS/Fedora users, you can view the /etc/login.defs files.
- To delete a user with home directory, you can use the advanced way by following these steps on your Linux server machine. When users are logged on to the server, they use services and run different processes. It is important to note that user can only be deleted effectively when they are not logged on to the server.
Lock User Accounts in Linux
Start by locking the user account password so that there is no access for the user to the system. This will prevent a user from running processes on the system.
The passwd command including the –lock option can help you achieve this:
Delete/Remove User Account and Files
Now you can safely remove user together with his/her home directory, to remove all user files on the system use the –remove-all-files option in the command below:
from all these some commands we are deleting or removing user in linux from home directory and from checking we are using ls -l command with the help of these all you are checking nd removing the entries of users.