How to check if a user has password on Linux

Any user created on Linux may or may not have a password. Linux stores passwords in encrypted format in /etc/shadow. Here is quick command line code to find if a user has password set.

$ sudo cat /etc/shadow | grep www-data

Second field in above output is *. That means user does not have an encrypted password set. Sometime you may also see “!” or empty string as placeholder for password. That also means that password is not set.

Here is an entry for a user which has password set:

$ sudo cat /etc/shadow | grep user2

Note the value of a valid encrypted password “$1$KNO15fOz$xMef3ieizYZmKrbhK1IAR/”. It also has the seed “KNO15fOz” in it.

Delete password for a user

In case you want to delete password for a user, you can run

$ sudo passwd -d user2
passwd: password expiry information changed.
$ sudo cat /etc/shadow | grep user2
Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit


Click here to write/view comments