Skip to content

Instantly share code, notes, and snippets.

@zph
Created September 19, 2019 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zph/eea83e2623fc4f34efebe0187aa2c89a to your computer and use it in GitHub Desktop.
Save zph/eea83e2623fc4f34efebe0187aa2c89a to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Creates alnum passwords of roughly the length requested.
# Alt form xxd -g 2 -l 64 -p /dev/urandom | tr -d '\n'
# (But then has a smaller random space b/c it's [a-f0-9].
# We ask openssl for COUNT * 4 to be overly safe that we'll have that amount
# available after stripping it down to only alphanumeric characters.
set -CEeuo pipefail
IFS=$'\n\t'
shopt -s extdebug
COUNT=${1:-25}
FULL_COUNT=$((COUNT * 4))
openssl rand -base64 "$FULL_COUNT" | tr -cd "[:alnum:]" | head -c "$COUNT"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment