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.

 

 

The following two tabs change content below.
Mr Surendra Anne is from Vijayawada, Andhra Pradesh, India. He is a Linux/Open source supporter who believes in Hard work, A down to earth person, Likes to share knowledge with others, Loves dogs, Likes photography. He works as Devops Engineer with Taggle systems, an IOT automatic water metering company, Sydney . You can contact him at surendra (@) linuxnix dot com.