Skip to content

Instantly share code, notes, and snippets.

@darookee
Created November 3, 2015 14:25
Show Gist options
  • Select an option

  • Save darookee/bc3d61ab0a5a312834ed to your computer and use it in GitHub Desktop.

Select an option

Save darookee/bc3d61ab0a5a312834ed to your computer and use it in GitHub Desktop.
Generate random passwords
#!/bin/bash
#
# Usage: ${0} <length> <count> <hex or alpha>
# Example: ${0} 12 1 h
# ${0} 32 2
# ${0}
alnum="[:digit:][:alpha:]"
hex="a-f[:digit:]"
if [ "${3}" == "h" ]; then
pwtype=$hex
else
pwtype=$alnum
fi
env LC_CTYPE=C tr -dc $pwtype < /dev/urandom | fold -w ${1:-32} | head -n ${2:-1}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment