Some services require you to generate random hex numbers to be used as a password or random auth token for authentication. The simplest method is to use this openssl cli command
openssl rand -hex 24

Free and Open Source blogger with an attitude
Some services require you to generate random hex numbers to be used as a password or random auth token for authentication. The simplest method is to use this openssl cli command
openssl rand -hex 24
Using openssl rand -hex 24 is a clean one-liner when a service wants a bearer token, and it is easy to miss that 24 bytes become 48 hex characters. Bookmarking that instead of piping urandom through several tools saves a few minutes next time.
Using openssl rand with the hex option is so much tidier than piping urandom through several tools when a service wants a random bearer token. Handy one-liner to bookmark for the next time an API asks for a secret.
Handy one-liner. It’s worth noting for anyone skimming that rand -hex 24 gives 48 hex characters because each byte becomes two, which is exactly why the 24 matches the title.
Handy reminder that openssl rand -hex 24 gives you the 48 hex characters, since the argument counts bytes rather than output characters. I have reached for a Python one-liner for bearer tokens before when this was already on the box.
openssl rand -hex 24 is the exact one-liner I keep losing whenever a service asks for a bearer-style hex token. Bookmarking this for the next time a password field wants forty-eight hex characters and nothing else.
Remembering that -hex 24 yields 48 hex characters (bytes×2) saves the usual off-by-one when someone asks for a 48-char bearer token. Keeping the openssl one-liner next to the auth-token use case is more useful than another /dev/urandom pipeline.
openssl rand -hex 24 as a one-liner for a 48-character bearer token is exactly the kind of short ops note I bookmark. Glad you called out auth-token use rather than leaving it as a generic “random hex” tip.
Handy tip, I usually reach for a Python snippet when I need a bearer token, but openssl is already on every server I touch. Worth remembering that the byte count you ask for is half the number of hex characters you get back.
openssl rand -hex 24 is a neat one-liner for a 48 character token, far simpler than piping /dev/urandom through other tools. Handy to have it written down somewhere easy to find.
My own setup uses a different key size for security reasons. That changes how many characters you need to produce.
Hi HexToken1, that’s a great point! Adjusting the byte count in the OpenSSL command makes it super flexible depending on your specific security requirements and target string length. Thanks for sharing how you handle it in your setup!