Skip to content

Instantly share code, notes, and snippets.

@jsumners
Created November 7, 2016 14:58
Show Gist options
  • Select an option

  • Save jsumners/3d639712a7dda2ba1e43ca5fe89dedbe to your computer and use it in GitHub Desktop.

Select an option

Save jsumners/3d639712a7dda2ba1e43ca5fe89dedbe to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# This script is for generating a random password, setting it for a specified
# user, and sending that password to a remote listener.
WHO=$(whoami)
# target user for password change
USER=jsumners
RECVR="10.0.0.10"
PORT=8000
if [ $WHO != "root" ]; then
echo 'need to be root'
exit 1
fi
PASS=$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-16};echo;)
echo "$USER:$PASS" | chpasswd
if [ $? -eq 0 ]; then
echo "$(hostname): $PASS" | nc $RECVR $PORT
else
echo "$(hostname): FAILED" | nc $RECVR $PORT
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment