Skip to content

Instantly share code, notes, and snippets.

@darookee
Created August 18, 2016 07:50
Show Gist options
  • Select an option

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

Select an option

Save darookee/c3b59e47fd62264112622b5a64d6e12b to your computer and use it in GitHub Desktop.
generate random password (hex or alphanumeric)
#!/bin/bash
# generate a random password from /dev/urandom
# usage: rpass <pwlength> <number_of_passwords> <h for hex>
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