Generate random passwords under GNU/Linux...
Submitted by msameer on Sat, 11/02/2006 - 1:30am
Well, I want to generate random passwords for people I give subdomains.
Since creating the subdomain involves a lot of steps, I decided to automate it a bit.
And since I only install the most needed things on the server, I decided to create a small script to generate the random password for me as I don't feel like installing a password generator.
dd if=/dev/random count=10 bs=1 | hexdump | cut -d \ -f 2-| head -n 1 | tr -d " "Now the only 2 problems with the above script are:
1) No upper case letters.
2) No special characters.
I don't really think that the above problems are fatal since the user will change the password after that to something stupid, Why ? Because users are idiots, They are not as smart as me ;-)
Under:










you can limit how man uppercase characters and how many spacial characters needed on your passwd
$ makepasswd --char=10
I don't want to install additional things.
For the sake of learning, I'll have a look at its source code to see how it's done ;-)
Try somthing like this and you can pick what chars you want by editing the sed.
dd if=/dev/urandom count=200 bs=1 2>/dev/null|tr "\n" " "|sed 's/[^a-zA-Z0-9]//g'|cut -c-16Here is what I came up with:
head -c 200 /dev/urandom | tr -cd '[:graph:]' | head -c 8
Why
head -c 200 /dev/urandominstead of simply
cat /dev/urandom?try it ?
Use md5sum for better passwords:
dd if=/dev/urandom count=128 bs=1 2>&1 | md5sum | cut -b-10
Note '2>&1', this makes sure dd's stderr output is piped to md5sum, instead of your terminal.
I use:
head /dev/urandom | uuencode -m -
It depends on uuencode, obviously, but usually it's installed by default. Advantages over other methods: complete uppercase and lowercase alphabet, digits and some symbols (+, /).
Regards!