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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s