Skip to content

Instantly share code, notes, and snippets.

@MatMercer
Created January 28, 2023 19:53
Show Gist options
  • Save MatMercer/1f54a523679653250080ca03f611bb1c to your computer and use it in GitHub Desktop.
Save MatMercer/1f54a523679653250080ca03f611bb1c to your computer and use it in GitHub Desktop.
Generate bcrypt password from command line

Generate a 16 chars password

excludechars=\`

htpasswd -bnBC 10 "" $(pwgen -sncBy -r "$excludechars" 16 1 | tee /dev/tty | tr -d '\n') | tr -d ':'
  • htpasswd -bnBC 10 ""
    • -b use password from command line
    • -n send to stdout
    • -B use bcrypt
    • -C 10 bcrypt computing cost
    • "" username, not used
  • pwgen -sncBy -r "$excludechars" 16 1
    • -s secure
    • -n at least 1 number
    • -c at least one capital letter
    • -B avoid ambiguius chars like lI
    • -y include one symbol
    • -r "$excludechars" exclude chars
    • 16 pw size
    • 1 generate one
  • | tee /dev/tty
    • to print the password and pass along
  • | tr -d '\n' to remove new line that pwgen adds
  • | tr -d ':' to remove : that htpasswd adds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment