Skip to content

Instantly share code, notes, and snippets.

@marvinroman
Last active August 4, 2018 01:20
Show Gist options
  • Save marvinroman/e54965b21b8f8d6b2640 to your computer and use it in GitHub Desktop.
Save marvinroman/e54965b21b8f8d6b2640 to your computer and use it in GitHub Desktop.
UNIX random password generator
#!/bin/bash
# Creator [email protected]
#
# Create's random password
# Should work on Most UNIX systems
# Default with special characters with a length of 12
# Optional -a (alphanumeric)
# Optional -l <number> (length)
usage() { echo "Usage: $0 [-a] [-l <length>]" 1>&2; exit 1; }
CHARS='A-Za-z0-9_%#*@5k^&!$'
LENGTH=12
while getopts "ahl:" o; do
case "${o}" in
a)
CHARS='A-Za-z0-9_'
;;
l)
LENGTH=${OPTARG}
;;
h)
usage
;;
*)
exit 1
;;
esac
done
shift $((OPTIND-1))
export LC_CTYPE=C
tr -dc "${CHARS}" < /dev/urandom | head -c ${LENGTH} | xargs
@marvinroman
Copy link
Author

To install just download, move to /usr/local/bin and make it executable.

curl -s "https://gist.githubusercontent.com/marvinroman/e54965b21b8f8d6b2640/raw/randpw.sh" > ~/randpw
sudo mv ~/randpw /usr/local/bin/
sudo chmod +x /usr/local/bin/randpw

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment