Sign in to follow this  
Followers 0
BooY

Search for no password entries and lock all accounts

1 post in this topic

Some script from www.tuxien.org


#!/bin/bash
# Shell script for search for no password entries and lock all accounts
# -------------------------------------------------------------------------
# Copyright (c) 2005 nixCraft project <http://cyberciti.biz/fb/>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------
# Set your email
ADMINEMAIL="
admin@somewhere.com This e-mail address is being protected from spambots. You need JavaScript enabled to view it
"

### Do not change anything below ###
#LOG File
LOG="/root/nopassword.lock.log"
STATUS=0
TMPFILE="/tmp/null.mail.$$"

echo "-------------------------------------------------------" >>$LOG
echo "Host: $(hostname), Run date: $(date)" >> $LOG
echo "-------------------------------------------------------" >>$LOG

# get all user names
USERS="$(cut -d: -f 1 /etc/passwd)"

# display message
echo "Searching for null password..."
for u in $USERS
do
# find out if password is set or not (null password)
passwd -S $u | grep -Ew "NP" >/dev/null
if [ $? -eq 0 ]; then # if so
echo "$u" >> $LOG
passwd -l $u #lock account
STATUS=1 #update status so that we can send an email
fi
done
echo "========================================================" >>$LOG
if [ $STATUS -eq 1 ]; then
echo "Please see $LOG file and all account with no password are locked!" >$TMPFILE
echo "-- $(basename $0) script" >>$TMPFILE
mail -s "Account with no password found and locked" "$ADMINEMAIL" < $TMPFILE
# rm -f $TMPFILE
fi

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0