Wednesday, February 17, 2010

» Generate a moderately secure random password

Just to remind myself... ;)
cat /dev/urandom \
| base64 \
| tr -d '[^:alnum:]' \
| cut -c1-10 \
| head -1
The command chain above does the following:
  • dd if=/dev/urandom: read random data from /dev/urandom and write it to STDOUT
  • base64: encode that binary data into Base64 to make it human-readable
  • tr -d '[^:alnum:]': remove all characters that are not alphanumeric (i.e. remove whitespaces, +, ...)
  • cut -c1-10: only keep characters 1 to 10 from each line
  • head -1: only keep the first line
Better randomness may be achieved by doing a cat on /dev/random instead of /dev/urandom, if you have enough entropy (see cat /proc/sys/kernel/random/entropy_avail) Obviously, if you prefer passwords of a different length, e.g. 16, change the cut -c1-10 accordingly: cut -c1-16

Labels: ,


Blogger localhost said...

pwgen isn't good enough? ;-)

Blogger Unknown said...

I prefer : pwgen -sy 10

Blogger Paul Cobbaut said...

Wasn't there a study a while ago that proved that taking the first letter of every word in an English sentence has the same level of security ?

(I would like to have 3 cups of coffee Now)

(Give me a two week holiday after Easter)

Blogger Unknown said...

Interesting construction but it still casting "+" and "/" chars.
To not to alter "tr" part from "tr -d '[^:alnum:]'" to "tr -d '[^:alnum:][/+]'"

Blogger j.eng said...

Secure passwords are not just random, but also memorizable. vxrandpw generates such by default.


Post a Comment

<< Home