How to generate your own Random Passwords?


If you don't have any password generating tools/commands like pwgen and makepasswd, you can follow the steps given below to create a command to generate passwords. These step enables a new command genpasswd for you.

   $ cd
 ~$ vi .bashrc

Append the following code in the .bashrc file

#-----------------------------------------------------------------------------------------------------

genpasswd() {
        local l=$1
        local n=$2
        [ "$l" == "" ] && l=16
        [ "$n" == "" ] && n=1

        while [ $n -gt 0 ]
        do
                tr -dc A-Za-z0-9_ < /dev/urandom | head -c ${l} | xargs
                n=$[$n-1]
        done
}
#------------------------------------------------------------------------------------------------------
save and quit from the file

~$ source .bashrc
   To executes the content of .bashrc, ie, to reload .bashrc.

Now the genpasswd command is available in your terminal.

General format of genpasswd command is as follows

$ genpasswd <number_of_character>  <no_of_passwords>

Examples:-

1.If you want to generate a random password with 12 character,
    $ genpasswd 12
2.By default,
   $ genpasswd
    Generate a random password with 16 character.
3.If you want to generate 5 passwords with 11 character each,
   $ genpasswd 11 5



Note:- You can use one of the following code instead of tr -dc A-Za-z0-9_ < /dev/urandom | head -c ${l} | xargs in genpasswd() function.

1. date | md5sum | head -c ${l} | xargs
2. openssl rand -base64 128 | head -c ${l} | xargs
3. strings /dev/urandom | tr -dc .~?_A-Z-a-z-0-9 | head -c ${l} | xargs

This entry was posted by Unknown. Bookmark the permalink.

Leave a Reply