Generate Random String Using The Linux urandom File

The /dev/urandom is a character special device file that allows for cryptographically secure random bytes to be generated. The output is in binary, so you need to convert it using base64 to get a random string out of it.

To create a random string containing 32 bytes of data.

head -c 32 /dev/urandom | base64

Note that this isn't 32 characters as the output can depend on that binary data is generated.

Add new comment

The content of this field is kept private and will not be shown publicly.