A simple Password-generating Bash Script

Most password safes have a generator for the password field when you are making a new entry.  Password Corral is a good example of this.  However, if you’re like me and like doing most things in a terminal, I wrote a fairly simple bash script which you can place into a $PATH of your choice and execute from anywhere.  Here’s the interesting bits:

https://strikerttd.fedorapeople.org/files/scripts/randompass.sh.txt

#! /bin/bash

# This simple script will generate a password with the following:
# Uppercase Letter, Lowercase Letter, Number, Special Character
#
# Length of password is determined by a provided variable.
# The default password length is 8 characters.

rpassLN=’a-zA-Z0-9′
rpassS=’!-_@#$%^&*()+{}:<>?=’

echo ; echo “Generate random passwords.” ; echo
echo “How many? Default = 4” ; read rpassA
echo “How long? Default = 8” ; read rpassL

if [[ -z $rpassA ]]
then
rpassA=4
fi

if [[ -z $rpassL ]]
then
rpassL=8
fi

echo ; cat /dev/urandom | tr -dc “$rpassS$rpassLN” | fold -w ${rpassL} | head -n ${rpassA}

The best places to put this would be into ~/.local/bin or ~/bin (again, depending on your $PATH).  You can also remove or add to the symbols in ‘rpassS’ depending on your needs.  Just make sure that the dash (-) is not listed as the first symbol……

Advertisements