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:
Append the following code:
Save and close the file. Source ~/.bashrc again, enter:
To generate random password, enter:
To generate 8 character long random password, enter:
You can use the following shell function to generate random password. Edit ~/.bashrc file, enter:
Code:
$ vi $HOME/.bashrc
Code:
genpasswd() { local l=$1 [ "$l" == "" ] && l=16 tr -dc A-Za-z0-9_ < /dev/urandom | head -c ${l} | xargs }
Code:
$ source ~/.bashrc
Code:
$ genpasswd
Code:
$ genpasswd 8
Comment