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: ,

5 Comments:

Blogger localhost said...

pwgen isn't good enough? ;-)

09:57  
Blogger Thomas said...

I prefer : pwgen -sy 10

11:55  
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 ?

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

Gma2whaE
(Give me a two week holiday after Easter)

12:24  
Blogger Meridius said...

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

02:55  
Blogger jengelh said...

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

01:07  

Post a Comment

Links to this post:

Create a Link

<< Home