random password generator in bash

Here is small but powerfull aliast for .bashrc file. It will generate strong passwords. Just put this in Your .bashrc file:

genpasswd() {
	local l=$1
       	[ "$l" == "" ] && l=20
      	tr -dc A-Za-z0-9_ < /dev/urandom | head -c ${l} | xargs

And from now on You can generate password with genpasswd command in the terminal.

To run it:

$ genpasswd 16

And output:


The number in command indicates what should be the lenght of generated password.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.