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

by nixcraft on December 19, 2005 · 0 comments

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:

Featured Articles:

Share this with other sys admins!
Facebook it - Tweet it - Print it -

We're here to help you make the most of sysadmin work. So, subscribe!

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 9 + 5 ?
Please leave these two fields as-is:
Are you a human being? Solve the simple math so we know that you are a human and not a bot.



Previous post:

Next post: