This blog post is dedicated to “rwman os” for contacting me to suggest that I was wrong !
And indeed I was !! ( <— two exclamation marks)
So this blog post create true random passwords has some mistakes and I am here to make amens.
the correct syntax on creating random passwords is this:
$ cat /dev/urandom | tr -dc $'\x21-\x7E' | head -c 21
and after further investigation (with GNU coreutils 8.23) seems that you can use octal as well:
$ cat /dev/urandom | tr -dc '\041-\176' | head -c 21
There is an errata blog post for this one !!!
$ cat /dev/urandom | tr -dc '[\x21-\x7E]' | head -c 16
(Not so) Long Story:
In Linux (we trust) we have a device that create randomness, named: /dev/random
The problem with this device is that the pool entropy (is something useful, believe me) can ran out very quickly.
So instead of random we use urandom. This device takes some output and re-entering it into the pool entropy, so that the entropy pool can never be empty.
Enough with all this tech crap … nobody truly cares …
We want to take some randomness from /dev/urandom … but … the output isnt something useful:
$ cat /dev/urandom | head
so we need to take only the ASCII printable characters from that output.
Looking at the ascii table, we found out that the printable characters starts from:
hexadecimal: 21 to hexadecimal: 7E
So to get the first n characters we can use the head command.
To get the first 16 characters: head -c 16
To put everything together:
$ cat /dev/urandom | tr -dc '[\x21-\x7E]' | head -c 16 JY`Fidt:sI>KoElR $ cat /dev/urandom | tr -dc '[\x21-\x7E]' | head -c 16 LH[lskwStlgM: $ cat /dev/urandom | tr -dc '[\x21-\x7E]' | head -c 16 Eifen5W1F@Vrqsc