Script to require password change at next login
Posted 12-02-2008 at 05:11 PM by camh
Hi all,
I wrote up this little script to force a password change to a user account on next login. I've found it helpful when doing user administration, since I've found that users generally don't change their passwords unless you force it, and linux doesn't have a 'built-in' script to do so.
Please note that I have hardcoded the salt into the script (denoted by 'TK' in the python command) because my use of this script is for assigning temporary passwords and as such the salt is not that important.
PS: I'm no script wizard, so I'm sure it could be optimized. But, it's functional, which is all that counts
Hope this helps somebody.
-camh
I wrote up this little script to force a password change to a user account on next login. I've found it helpful when doing user administration, since I've found that users generally don't change their passwords unless you force it, and linux doesn't have a 'built-in' script to do so.
Code:
#!/bin/bash if [ "$(whoami)" != 'root' ]; then echo "This program must be run as root" exit 1; elif [ -z $1 ]; then echo "Usage: pwexpire <username>" exit 1; elif [ ! `grep $1 /etc/passwd` ] ; then echo "$1 not found. Please ensure the user account exists." exit 1; elif [ ! -f /usr/bin/python ] ; then echo "Python not found in /usr/bin!" exit 1; fi echo -e "Please enter the temporary password: \c " read TMPPASS if [ ! -f /root/pwconv-tmp.py ]; then echo "import crypt; print crypt.crypt(\"$TMPPASS\",\"TK\")" > /root/pwconv-tmp.py PWHASH=`/usr/bin/python /root/pwconv-tmp.py` usermod -L $1 && chage -d 0 $1 usermod -p "$PWHASH" $1 echo "Operation successful. Account $1 will require a password change on next login" rm /root/pwconv-tmp.py exit 0; else echo "An error occured. Please re-run this program" exit 1; fi
PS: I'm no script wizard, so I'm sure it could be optimized. But, it's functional, which is all that counts

Hope this helps somebody.
-camh
Total Comments 0