Saturday, November 22, 2008

Generating random passwords

Here are a couple of ways of generating random passwords without using a "password generator". First, generate a random string like this:
$ dd if=/dev/urandom count=500 bs=1 | tr "\n" " " | sed 's/[^a-zA-Z0-9]//g'
or like this
$ dd if=/dev/urandom count=500 bs=1 | md5
Then adjust the length by piping the output through cut(1):
... | cut -c-8
While the first option is more to type, it generates lower and upper case letters. The second option is easier to type but only generates lower-case passwords.

Update (Dec 12th, 2008): Fixed error. cut(1) must be used, not cat(1).

No comments: