random passwords

In my quest to make my life easier and at the same time find clever ways to do things, I have run across a neat way to generate random passwords.

After seeing this post I wrote genpass.sh.

Before I have used utilities like makepasswd and passgen.pl by Andrew 'Skinny' Thompson.

What I liked about the foolab.org version was that it was very portable. It uses /dev/urandom to get the random bits and then uses standard *nix tools to turn it into a password.

The bit that does most of the work in the genpass.sh script is:

( dd if=/dev/urandom count=200 bs=1 2>/dev/null |
tr '\n' ' ' ; echo ) |
sed 's/[^a-kmnp-zA-HJ-NP-Z2-9|\+=@#$%^&*()]//g' |
cut -c-"${length}"

The sed statement strips out commonly misread characters, o, O, 0, l, I, 1.

genpass.sh has been tested on Debian 3.1, Ubuntu 6.10, FreeBSD 6.2 and Solaris 9.