Script Name: SSH Key Authentication Generator
Language: Bash
Purpose: Automate generation of SSH key files (id_rsa & id_rsa.pub for example), for use with passwordless SSH authentication.
Notes: This is a modified version of a script I have on my blog, http://www.itknowledgeexchange.com/security-admin/ (direct link: http://itknowledgeexchange.techtarget.com/security-admin/bash-script-for-ssh-key-generation/ ) as I feel the automated version is a lot more resourcesful.
#!/bin/bash
# Make sure input is not printed to screen (since we are typing in a password after all)
stty -echo
read -p "Passphrase: " pp
stty echo
# ssh-keygen prohibits passphrases < 4 characters
if [ "${#pp}" -lt 4 ]; then
echo -e "nPassphrase must be greater than 4 characters."
exit 1
fi
# man ssh-keygen specifies that for RSA, 2048-bit keys are considered efficient.
bits=2048
# Debatable whether DSA or RSA is really more secure here, but RSA is more of the standard when it comes to this
enc="rsa"
# Default path where all keys are stored
kf="$HOME/.ssh/id_$enc"
# Check to see if the file exists first (if so, delete it)
echo -n "Checking to see if $kf exists (deleting if so)..."
if [ -e "$kf" ]; then
rm -rf $kf
fi
echo -e -n "done.nGenerating a $bits bit $enc key file for SSH ($kf)..."
ssh-keygen -q -b $bits -t $enc -N $pp -f "$kf"
if [ -e "$kf" ]; then
echo "done."
else
echo "error."
fi
exit 0
[/pre]
Software/Hardware used:
ASKED:
October 12, 2011 5:55 PM