Generate strong password inside bash shell

We can easily generate strong password directly from our terminal by adding this line to our ~/.bashrc file.

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

After we need to reload bashrc:

source ~/.bashrc

run genpass command in terminal and you will get randomly generated 20 symbol password.