From 94afc729f9d87590300f1b7a1f5172b874e491ae Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Thu, 12 Oct 2023 09:41:08 -0500 Subject: [PATCH] Add Generate Random 20-Character Hex String as a Unix TIL --- README.md | 3 ++- unix/generate-random-20-character-hex-string.md | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 unix/generate-random-20-character-hex-string.md diff --git a/README.md b/README.md index a2f88ea..5f4d74c 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186). -_1342 TILs and counting..._ +_1343 TILs and counting..._ --- @@ -1289,6 +1289,7 @@ _1342 TILs and counting..._ - [Fix Unlinked Node Binaries With asdf](unix/fix-unlinked-node-binaries-with-asdf.md) - [Forward Multiple Ports Over SSH](unix/forward-multiple-ports-over-ssh.md) - [Generate A SAML Key And Certificate Pair](unix/generate-a-saml-key-and-certificate-pair.md) +- [Generate Random 20-Character Hex String](unix/generate-random-20-character-hex-string.md) - [Get Matching Filenames As Output From Grep](unix/get-matching-filenames-as-output-from-grep.md) - [Get The Unix Timestamp](unix/get-the-unix-timestamp.md) - [Global Substitution On The Previous Command](unix/global-substitution-on-the-previous-command.md) diff --git a/unix/generate-random-20-character-hex-string.md b/unix/generate-random-20-character-hex-string.md new file mode 100644 index 0000000..ee31721 --- /dev/null +++ b/unix/generate-random-20-character-hex-string.md @@ -0,0 +1,17 @@ +# Generate Random 20-Character Hex String + +The `openssl` utility has a bunch of subcommands including `rand`. The `rand` +subcommand can be used to generate pseudo-random numbers. + +```bash +openssl rand -hex 10 +5ce459896581abc81a65 +``` + +The number at the end of the command tells `rand` how many bytes of output to +generate. When the `-hex` flag is used, it will encode the output in hex. + +The 10 bytes of output in hex will result in a 20-character string. That number +can be adjusted to your needs. + +See `man openssl` or `openssl rand -help` for more details.