skip to content
gill.coffee

Generate random characters for cryptographic use

Shell snippet to generate a random string of characters; use when in need of a cryptographic secret.

Terminal window
head /dev/urandom \
| LC_ALL=C tr -dc 'A-Za-z0-9!"#$%&'\''()*+,-./:;<=>?@[\]^_`{|}~' \
| head -c 24
  • Setting LC_ALL=C environment variable prevents system locale settings from affecting output
  • tr utility will strip out non-printable characters from the randomess source /dev/random
  • The supplied regex will allow all alphanumeric characters, plus characters from the OWASP password special characters list
  • Adjust the length of the resulting string with the -c flag of the head utility

Use the snippet below to copy the string to your system clipboard.

Terminal window
head /dev/urandom \
| LC_ALL=C tr -dc 'A-Za-z0-9!"#$%&'\''()*+,-./:;<=>?@[\]^_`{|}~' \
| head -c 24 \
| pbcopy

source