Notes
These notes are small problems I've encountered in my adventures in system administration and development. I'm documenting them to both help future me and anyone else who might face similar issues.
Often, you will want to generate random strings for identifiers, passwords or other use cases.
The advice I often see is to use openssl rand -base64 32. This method does work, but comes with some disadvantages:
- Base64 encoding can leave you with
/,=and+characters, which are usually undesirable - Specifying a number of bytes can make it bit tricky to get the string length you want
My preferred method (which I keep forgetting so I’m writing it down…) is to use:
$ tr -dc 'A-Za-z0-9' </dev/urandom | head -c 12
t3TpDEwZjkZr
This gives you a predictable length output, and you know exactly what characters will be included. If you want to include other characters, just add them to the tr command:
$ tr -dc 'A-Za-z0-9_\-!' </dev/urandom | head -c 12
!sn_CfP-LgI6
(Note the \ for the - character!)
On recent versions of Windows (seems to mainly be 24H2), I’ve noticed an increase in the number of “Port in Use” errors when trying to run development servers on Windows.
If, like me, you find yourself wondering why a port you know is free is being reported as in use, fear not!
The cause is to to with the reserved ports feature in Windows, which can handily reserve ports which you’re trying to use 🙄
The fix is simple, just restart the winnat service.
Restart-Service winnat
To show the reserved ports, you can use the following command:
netsh interface ipv4 show excludedportrange protocol=tcp