How to Disable Password on Linux User with Command

linuxpasswordSecurityshadow

Based on /etc/shadow(5) documentation on the second (password) field:

encrypted password

If the password field contains some string that is not a valid result
of crypt(3), for instance ! or *, the user will not be able to use a
unix password to log in (but the user may log in the system by other
means).

My question is whether there is a linux command to disable the user password,i.e. set a "*" or a "!" on password field.

Best Answer

You are looking for passwd -l user.

From man passwd:

Options:

[...]

-l, --lock lock the password of the named account. This option disables a password by changing it to a value which matches no possible encrypted value (it adds a '!' at the beginning of the password).

Related Question