Q. How can I disable or lock a password for a User in Linux?
Some times it’s required to lock user not to login to the machine. This can be done by using passwd command. this command should be executed by root or super user. Execute below command lock a user.
Syntax:
passwd -l username
Example:
passwd -l surendra.
The above command will lock the user surendra prominently so that he can not login to the machine.
Once the password is locked or disabled !(negation sybol) will be added to password field in /etc/shadow file for that user.
Before password lock implemented, the entry for surendra as below.
surendra:$6$rZnP7SSN$emBz/./WkjSa9B:15615:0:99999:7:::
After setting password lock:
surendra:!$6$rZnP7SSN$emBz/./WkjSa9B:15615:0:99999:7:::
If you try to login, you will get “Login incorrect“, This error is because ! in the password field of /etc/shadow file for user surendra.
Please follow our next post on unlocking the password.
Latest posts by Surendra Anne (see all)
- Docker: How to copy files to/from docker container - June 30, 2020
- Anisble: ERROR! unexpected parameter type in action:
Fix - June 29, 2020 - FREE: JOIN OUR DEVOPS TELEGRAM GROUPS - August 2, 2019
- Review: Whizlabs Practice Tests for AWS Certified Solutions Architect Professional (CSAP) - August 27, 2018
- How to use ohai/chef-shell to get node attributes - July 19, 2018