List Locked Accounts in Linux

Published by Torry Crass on

So you’re facing a system or security audit and you need to quickly print a list of accounts for the auditor as well as their statuses.

Depending on your setup, this could be a trivial task. In other cases, especially with a passwd instance that doesn’t support the -a option, this might be a bit tricky.

The following command set, when in bash shell and run from root, will list out all the accounts on a system as well as their statuses.

cat /etc/passwd | cut -d : -f 1 | awk '{ printf "User: " ; printf $0."\t\t Status: " ; system("passwd -S " $0) }'

In the event that you need to only list locked accounts you can simply append a grep statement such as in the example below.

cat /etc/passwd | cut -d : -f 1 | awk '{ printf "User: " ; printf $0."\t\t Status: " ; system("passwd -S " $0) }' | grep "locked"

0 Comments

Leave a Reply