FreeBSD: Finding passwordless (no password) account and lock all accounts

by on December 19, 2005 · 0 comments· LAST UPDATED December 19, 2005

in

It is necessary to check for passwordless accounts (i.e. search for no password entries and lock all accounts.) for security reasons. However, FreeBSD does not come with any command that can help you to find out all such accounts. FreeBSD stores password in /etc/master.passwd file. You can use awk to find out all passwordless account. Login in as root user and type following command:

awk -F: 'NF > 1 && $1 !~ /^[#+-]/ && $2=="" {print $0}'
/etc/master.passwd

s2099ms::1099:1099::0:0:User &:/home/s/s2099ms:/bin/bash

Where
NF : Total number of record (so only continue if we have more than one record in password file)
$1 : First field in /etc/master.passwd
$2 : Second filed in /etc/master.passwd
$1 !~ /^[#+-]/ : It compares first field (user login name) and make sure it does not starts with either +,- or # symbol

How does it work?
1) Awk statement read each line in /etc/master.passwd where fields separated by : symbol
2) Account has no password if password field ($2) in /etc/master.passwd is empty

Once you found all such passwordless account., you can Lock user account with the following command:
pw lock {username}

# pw lock  s2099ms

For unlocking the account use:
pw unlock {username}

# pw unlock s2099ms

Related articles:

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 0 comments… add one now }

Leave a Comment

Previous post:

Next post: