Cool Password Script

Today I got a cool password script working to change a bunch of accounts and email the passwords encrypted with GPG.

#!bin/bash
pushd /run
PWDFILE=hostname.txt
echo $PASSWORD
touch $PWDFILE
chmod 0600 $PWDFILE
echo "New Passwords" >> $PWDFILE
date >> $PWDFILE
hostname >> $PWDFILE
hostname -i >> $PWDFILE
for USER in alice bob charles david
do
  PASSWORD=apg -M LNC -n 1 -m 16 -x 20
  echo -e $USER" " >> $PWDFILE
  echo $PASSWORD >> $PWDFILE
  echo -e $PASSWORD"\n"$PASSWORD | passwd $USER
done
rm -f $PWDFILE.asc
gpg -r larry@example.com -a -e $PWDFILE
rm -f $PWDFILE
echo "New passworda for "hostname | mutt -s "New passworda for "hostname larry@example.com -a $PWDFILE.asc

Works really well.

Weight: 299.2

This entry was posted in Technical, Training, Weigh In. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.