13

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.

trikelef
  • 381
  • 1
  • 4
  • 13

2 Answers2

17

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).

terdon
  • 234,489
  • 66
  • 447
  • 667
Panki
  • 6,221
  • 2
  • 24
  • 33
0

You can simply disable password by just deleting it. You must have sudo privilege! use command:

sudo passwd -d <username>

Here is an coloum from man passwd:

-d, --delete Delete a user's password (make it empty). This is a quick way to disable a password for an account. It will set the named account passwordless.