Generate random string using OpenSSL
Basic usage to generate random string
openssl rand -hex [length]
Generate random string with specific length
Generate random string with 32 bytes length.
openssl rand -hex 32
The output will be:
9a64905a171a72ef0e06762bfd950d40612d615a80a6309083390f4dc7d826f9 # or something like this
When you use the -hex
option with openssl rand
command, it shows the random data as a series of hexadecimal numbers. The argument (number) 32
means it’s showing 32 bytes of data. This results in a string with 64 characters, because each byte is represented by two hexadecimal digits.