Wednesday, March 3, 2010

Linux Random Password Generator Command



How do I generate random passwords on the Linux command line using the bash shell?

You can use the following shell function to generate random password. Edit ~/.bashrc file, enter:
$ vi $HOME/.bashrc
Append the following code:
 
genpasswd() {
local l=$1
[ "$l" == "" ] && l=16
tr -dc A-Za-z0-9_ < /dev/urandom | head -c ${l} | xargs
}

Save and close the file. Source ~/.bashrc again, enter:
$ source ~/.bashrc
To generate random password, enter:
$ genpasswd
To generate 8 character long random password, enter:
$ genpasswd 8

No comments:

Post a Comment