Create complex password using shell script

Create complex password using shell script

In this blog we are going to see how to create complex password using shell scripting. Earlier we have seen about adding user and their respective password through shell script

Create complex password using shell script

 

As part of linux administrator work creating user’s and assigning complex password is an mandatory task. To make this work easier i have created the below shell script. The below shell script will ask input from user like number of password and password length. Then it creates complex password with the combination of values “a-zA-Z0-9-=\`@#$%^&*()”

[root@client ~/Desktop/Scripts] cat complexpassword.sh
#!/bin/bash
echo “Please enter the value in number. Characters are invalid”
echo -n “Enter number of letters password should have: “
read number_of_letters
echo -n “Enter number of Password required: “
read number_of_password
cat /dev/urandom | tr -cd “a-zA-Z0-9-=\`@#$%^&*()” | fold -w $number_of_letters | head -n $number_of_password

Let’s execute the shell script from command prompt

[root@client ~/Desktop/Scripts] sh complexpassword.sh
Please enter the value in number. Characters are invalid
Enter number of letters password should have: 8
Enter number of Password required: 4
7ycQHZwu
TEf@Q#hY
LwjH36RO
)Cyj0t3c

Create complex password using shell script




2 thoughts on “Create complex password using shell script

  1. Jared

    Very Well Done. However it doesn’t work with Cygwin because of how /dev/urandom outputs and because ” is not treated the same in cygwin.

    I have converted your script to work with Cygwin. Here is the Cygwin version

    #!/bin/bash

    echo ‘Please enter the value in number. Characters are invalid’
    echo -n ‘Enter number of letters password should have: ‘
    read number_of_letters
    echo -n ‘Enter number of Password required: ‘
    read number_of_password
    head -n $number_of_password /dev/urandom | tr -cd ‘a-zA-Z0-9-=\`@#$%^&*()’ | fold -w $number_of_letters | head -n $number_of_password

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *