This post will help you to delete password of user in linux. We should also know what is the exact reason we are deleting the password of user.
User and group management in any operating system always play an important role. In Linux, sometimes we receive the request to disable the login of a user. So we can easily achieve this by either from these two methods –
1. Delete password of user.
2. Set nologin shell to user.
Lets first go quickly to method of deleting the password of an user and in end of the post we will show how to set nologin shell to user.
Delete password of user in Linux
Use the given below syntax. Replace user_name with your user account name for which you want to delete the password.
sudo passwd -d user_name
sudo passwd -d test
Here, in above example, we have delete the password of user account called ‘test’. Once we do this, user called ‘test’ will not be able to login in system.
Set nologin shell to user in linux
Once you set the nologin shell , user will not be able to login in system.
Syntax: In given below syntax format replace ‘username’ with your system user account name here.
sudo usrmod -s /sbin/nologin username
Here we are setting the nologin shell to user called test. Once the command is successfully completed, the user ‘test’ will not be able to login in system.
usrmod -s /sbin/nologin test
Check passwd and shadow file
1. Lets see what happen when we delete the password. The user account password are kept in /etc/shadow file, when we delete the password it will remove password information from /etc/shadow. Always remember, /etc/shadow file keep password in encrypted format.
In given below screenshot, you will find that after deleting the password some empty space in /etc/shadow file for user called ‘test’.
2. Default shell of user you can easily find from /etc/passwd file. In given below screenshot, user called ‘test’ shell is changed to /sbin/nologin shell and previously it had /bin/bash shell.