16

How find user with empty password in Linux?

met78
  • 293
  • 1
  • 2
  • 7

5 Answers5

17

This is a shorter and more precise version of AndreKR's answer:

sudo getent shadow | grep '^[^:]*:.\?:' | cut -d: -f1

It has only one call to cut and will find entries of any of the forms below:

foo:!: ...
bar:*: ...
baz:: ...

If you only want truly empty:

sudo getent shadow | grep '^[^:]*::' | cut -d: -f1

If you have GNU grep, you can eliminate cut completely:

sudo getent shadow | grep -Po '^[^:]*(?=:.?:)'

or

sudo getent shadow | grep -Po '^[^:]*(?=::)'
Dennis Williamson
  • 62,149
  • 16
  • 116
  • 151
9
getent shadow | cut -d: -f1-2 | grep ':$' | cut -d: -f1
AndreKR
  • 551
  • 1
  • 3
  • 17
6

Encrypted password is the second field in /etc/shadow.

If second field is empty, then password empty:

awk -F":" '($2 == "") {print $1}' /etc/shadow

! and * is invalid password(user can not login):

awk -F":" '($2 == "!" || $2 == "*") {print $1}' /etc/shadow
Mark Henderson
  • 68,823
  • 31
  • 180
  • 259
ooshro
  • 11,134
  • 1
  • 32
  • 31
2

Their entry in /etc/shadow/ will have no password-hash in it. You'll need to be logged in as root to be able to see them, though.

sysadmin1138
  • 133,124
  • 18
  • 176
  • 300
0

Has the user "user" an empty password ?

getent shadow | grep 'user:\$' | cut -d':' -f 2 | grep '\w' -c -m 1  

return 1 on fail - password is not empty
return 0 on success - a password is set

Hope this is accurate

LittleEaster
  • 111
  • 3