#!/bin/bash # # Filename: dist_keys.sh # Depends on: copy-keys-v.4.exp # Written by: WG 2009-02-04 # Updated 2009-08-01 # http://www.virtfoundry.com # wgoodric@virtfoundry.com # # Generate SSH keys and distribute by calling copy-keys-v.4.exp # # USER=`whoami` pass=$1 KEYGEN="/usr/bin/ssh-keygen" RSA_KEY="id_rsa" HOME="/home/$USER" DIR=".ssh" # # Have I already been run here? if [ -e $HOME/.dist_keys ] then echo "This utility has already been run. Please propagate" echo "new public keys manually using ssh-copy-id" exit fi # if [ ! -s nodes.txt ] then echo "nodes.txt not found or empty: Please populate nodes.txt with cluster nodes' hostnames" exit fi # Is expect here? if [ ! -x /usr/bin/expect ] then echo "I did not find the expect binary, please install expect" exit fi # Does our expect script exist? executable? if [ ! -x $CMD ] then echo "$CMD is either missing or not executable" exit fi # echo "Generating SSH keys"$'\n' if [ ! -d $HOME/$DIR ] then mkdir $HOME/$DIR chmod 755 $HOME/$DIR fi # $KEYGEN -q -t rsa -f $RSA_KEY -C '' -N '' cp $RSA_KEY $HOME/$DIR cp $RSA_KEY.pub $HOME/$DIR chmod 600 $HOME/$DIR/$RSA_KEY chmod 644 $HOME/$DIR/$RSA_KEY.pub chown $USER -R $HOME/$DIR rm -f $RSA_KEY $RSA_KEY.pub # CMD="./copy-keys-v.4.exp" PREFX="meta" # Ensure proper networking / hostfile setup here # If not ping by hostname, error out with notify # Get number of RAC hosts to set range here and ping them echo "Checking node network connectivity..."$'\n' while read host do if ! ping -c 3 $host >/dev/null 2>&1 then echo "I was unable to ping $host" echo "Please verify networking and /etc/hosts" exit fi done < nodes.txt # Launch expect script on all RAC hosts to propagate public key echo "Propagating public key to nodes..."$'\n' { while read host do $CMD $USER $host $pass done < nodes.txt } > propagate-keys.log touch $HOME/.dist_keys echo "Finished - a log is available in propagate-keys.log"