Skip to content

Instantly share code, notes, and snippets.

@mshuler
Created March 15, 2020 00:02
Show Gist options
  • Save mshuler/e7223ae59b914e12740d17647b049911 to your computer and use it in GitHub Desktop.
Save mshuler/e7223ae59b914e12740d17647b049911 to your computer and use it in GitHub Desktop.
Generate random password string on the CLI
#!/bin/bash
# Generate random password string from all printable, non-space
# characters, using passed argument for number of characters,
# defaulting to a 16-character string. For example:
# $ randpw
# XC6Jo]2fj&f4E45n
# $ randpw 24
# :U)#J]b5[0mg)Wp@M\)l`$\y
function randpw() {
tr -dc '[:graph:]' < /dev/urandom \
| head -c ${1:-16}
echo
}
randpw ${1}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment