- creates public key locally, if not yet generated;
- checks if public host is already there, and don't make a dup.
Must be executed on client side! It will copy public key to the server and concatenate with the authorized_keys file.
OPTS="-o StrictHostKeyChecking=no" #-v
if [ ! -e ~/.ssh/id_rsa.pub ]; then
echo "========= Generating public key, with empty passpharase..."
ssh-keygen -q -f ~/.ssh/id_rsa -t rsa
chmod 700 ~/.ssh
chmod go-rwx ~/.ssh/*
echo "========= Copy pubkey for the $L..."
scp $OPTS ~/.ssh/id_rsa.pub $L: 2>/dev/null
if [ $? == "0" ]; then
echo "========= Setup the public key for $L and permissions there..."
ssh $OPTS $L '
if [ ! -e ~/.ssh ]; then mkdir ~/.ssh; chmod 700 ~/.ssh; fi;
grep -q -s `head -1 ~/id_rsa.pub | cut -d " " -f 2` authorized_keys;
if [ $? != 0 ]; then cat ~/id_rsa.pub >> authorized_keys; echo "Key added";
else echo "Key was already there"; fi;
chmod 600 authorized_keys;
Enter empty passphrase when asked during ssh key generation.
Tested on AIX, but should run perfect (ksh) on other systems without modifications.