Password factory

A quick tip to easily generate random password from a bash command line.

Add the following lines to your bashrc file:

alias genalphanumpasswd='tr -cd '\''[:alnum:]'\'' < /dev/urandom | fold -w30 | head -n1'
alias genpasswd='tr -cd '\''[:graph:]'\'' < /dev/urandom | fold -w30 | head -n1'

Save and source it:

. ~/.bashrc

Then you can use it:

$ genalphanumpasswd
$ genalphanumpasswd

The first alias, based on [:graph:], produces passwords made of all printable ascii characters except space.

The second one, based on [:alnum:], produces passwords made of A-Z, a-z, 0-9 characters only. This can be usefull depending on the target application.