//View Tip #161
Similar Tips
» Bash terminal size
» Fix the previous command
» another solution to #67
» swap files
» Remove empty directories

 

Latest tips by RSS
Click here to subscribe
Follow Shell-Fu on Twitter
Click here to follow
Follow Shell-Fu on identi.ca
Click here to follow
This is a simpler password generator.

< /dev/urandom tr -dc A-Za-z0-9_ | head -c8

Note that the 'tr' strips out everything except characters in the ranges (alphanumeric, mixed case and underscores). This is a nice approach as piping to head means the minimum number of bytes required to generate a password of appropriate length are taken from /dev/urandom vs other methods which take more than you should need but still have a chance of not having obtained enough random data to generate a password of the required length. You can change the parameter to head to get passwords of any length.


View Comments »




Comments 

Add your comment

Comments are currently disabled
To get a newline do this:

< /dev/urandom tr -dc A-Za-z0-9_ | head -c8 ; echo
Posted 2009-02-08 00:45:55
Seb
Another way to do it:

dd if=/dev/urandom ibs=6 count=1 2>/dev/null | base64
Posted 2009-02-24 23:53:31
Jesse
You can add special chars as well.

< /dev/urandom tr -dc 'A-Za-z0-9[=!=][=$=][=@=][=%=][=^=]' | head -c9 ; echo
Posted 2009-06-04 15:31:56
Marcel
Thanks! That was just what I was looking for!

This is what I use for strong passwords:

< /dev/urandom tr -dc [:graph:] | head -c 256; echo

or base64 encoded, so nobody sees it  accidentally.

< /dev/urandom tr -dc [:graph:] | head -c 256| uuencode -m -
Posted 2009-07-24 06:22:16

Home Latest Browse Top 25 Random Hall Of Fame Contact Submit