Last active
August 4, 2018 01:20
-
-
Save marvinroman/e54965b21b8f8d6b2640 to your computer and use it in GitHub Desktop.
UNIX random password generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To install just download, move to /usr/local/bin and make it executable.