Generate random characters for cryptographic use
Shell snippet to generate a random string of characters; use when in need of a cryptographic secret.
head /dev/urandom \| LC_ALL=C tr -dc 'A-Za-z0-9!"#$%&'\''()*+,-./:;<=>?@[\]^_`{|}~' \| head -c 24- Setting
LC_ALL=Cenvironment variable prevents system locale settings from affecting output trutility 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
-cflag of theheadutility
Use the snippet below to copy the string to your system clipboard.
head /dev/urandom \| LC_ALL=C tr -dc 'A-Za-z0-9!"#$%&'\''()*+,-./:;<=>?@[\]^_`{|}~' \| head -c 24 \| pbcopy