Skip to content

Instantly share code, notes, and snippets.

@seqizz
Last active August 29, 2015 14:00
Show Gist options
  • Save seqizz/e6637b991901c327949e to your computer and use it in GitHub Desktop.
Save seqizz/e6637b991901c327949e to your computer and use it in GitHub Desktop.
Bulk Change Password
#!/bin/bash
# requires "empty": http://empty.sourceforge.net/
# ubuntu users also should check http://ubuntuforums.org/showthread.php?t=2131632
function helpshow() {
echo "
Usage:
$0 192.168.1.5 192.168.1.6
"
exit 1
}
if [ $# == 0 ] ; then
helpshow
fi
echo -n "username: "
read login
echo -n "current password: "
read -s password
echo ""
echo -n "new password: "
read -s newpass
# -----------------------------------------------------------------------------
for target in $@; do
cmd="ssh $login@$target passwd"
tmp="/tmp/empty.tmp"
empty -f -L $tmp $cmd
if [ $? = 0 ]; then
empty -v -w assword: "$password\n"
empty -v -w assword: "$password\n"
#don't cry, we need to roll 4 times in case of pam_passwdqc
for i in 1 2 3 4; do
empty -v -w assword: "$newpass\n"
done
empty -s "exit"
sleep 1
#want verbosity? uncomment next line
#cat $tmp
rm -f $tmp
else
echo "Error: Can't start empty in daemon mode"
return 1
fi
echo "$target DONE"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment