I'm trying to generate random and secure passwords to my various configuration files and settings on the fly when I run my automated deployment script. I want them to be generated, shown to the user, used as part of the deployment and then discarded.
This is what I was going with:
# FUNCTION TO GENERATE A RANDOM STRING
function randpass() {
[ "$2" == "0" ] && CHAR="[:alnum:]" || CHAR="[:graph:]"
cat /dev/urandom | tr -cd "$CHAR" | head -c ${1:-32}
echo
}
$NOW = $(date +"%m-%d-%Y") || echo ="Time = $now"
$APPKEY = randpass(20) || echo "Secret key = $APPKEY"
read -p "Copied down?" -n1 -s
- Is this a bad approach?
- Is this secure?
- Will the passwords be stored as variables after deployment has finished?
I'm new to shell and linux administration so any help is appreciated.
James