May
23
2015
Create TRUE random passwords


There is an errata blog post for this one !!!

tldr;


$ 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

urandom.jpg

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
Tag(s): random, password