#!/bin/bash echo "Version 07222k3-a/CLUSTERKNOPPIX-CD. SSH2 MasterKey Generation/Compilation Script." echo "Where is the master authorizedkeys file?" echo "What would you like to name the masterkeys file?" read MASTER_AUTHKEYS2 cd ~/.ssh pwd touch ~/.$MASTER_AUTHKEYS2 echo "We are working with" ls ~/.ssh/$MASTER_AUTHKEYS2 echo "as our master authorized keys file." LOCAL=`hostname` echo "=============================================" echo " SSH2 KEY GENERATION AND ACQUISITION " echo "=============================================" J=0 for GETHOST in `cat /do_ssh_hosts`; do clear J=`expr $J + 1` echo "Iteration #: $J: Processing: $GETHOST" echo "Do you REALLY want to gen a new key for $GETHOST?" read DUMMY case "$DUMMY" in y|Y|Yes|YES|yes) echo "Generating key..." ssh $GETHOST ssh-keygen -t rsa ;; *) echo "USING EXISTING KEY on $GETHOST." ;; esac echo "Acquiring public key..." scp $GETHOST:~/.ssh/id_rsa.pub ~/.ssh/$GETHOST.id_rsa_pub echo "Keys acquired so far." ls -al ~/.ssh/*.id_rsa_pub done echo "=============================================" echo " MASTER KEY FILE COMPILATION" echo "=============================================" echo "Nuking old masterkey file of name $MASTER_AUTHKEYS2" rm ~/.ssh/$MASTER_AUTHKEYS2 for FILE in `echo *.id_rsa_pub`; do cat ~/.ssh/$FILE >>~/.ssh/$MASTER_AUTHKEYS2 if [ $? -ne 0 ]; then echo "Compilation of $MASTER_AUTHKEYS2 failed." exit 1 fi done clear echo "=================================================================" echo " Populating cluster with new masterkeys file for user `whoami`." echo " Optionally removing the existing known_hosts file..." echo "=================================================================" echo "This will disseminate copies of the $MASTER_AUTHKEYS2 file to each" echo "node in the do_ssh_hosts file." echo "Do you wish to proceed?" read DUMMY J=0 case "$DUMMY" in y|Y|YES|yes|Yes) for GETHOST in `cat /do_ssh_hosts`; do clear J=`expr $J + 1` echo "Iteration #: $J: Sending master keys to $GETHOST:" scp ~/.ssh/$MASTER_AUTHKEYS2 $GETHOST:~/.ssh/authorized_keys2 echo 'This will remove the existing .ssh/known_hosts...' echo "Do you wish to proceed?" read DUMMY case "$DUMMY" in y|Y|Yes|YES|yes) echo 'Removing .ssh/known_hosts.' ssh $GETHOST rm ~/.ssh/known_hosts ;; *) echo "I am not touching the known_hosts file on $GETHOST." ;; esac echo "=====> RESTARTING SSH on $GETHOST <=====" echo "-------- DEBIAN RESTART ---------" ssh root@$GETHOST /etc/init.d/ssh restart if [ $? -ne 0 ]; then echo "Debian Restart for $GETHOST failed. Host probably down/not Debian." echo "Try again with Redhat Restart?" read DUMMY case "$DUMMY" in y|Y|YES|yes|Yes) echo "------- RHAD RESTART -------" ssh root@$GETHOST /etc/init.d/sshd restart if [ $? -ne 0 ]; then echo "RHAD Restart failed. $GETHOST is probably down." fi ;; *) echo "I am not trying again on this host. You" echo "have to restart $GETHOST's ssh daemon" echo "au natural (manually)." ;; esac echo "Continue with next host?" read DUMMY case "$DUMMY" in y|Y|YES|yes|Yes) echo "Continuing." ;; *) echo "Aborting with failure at $GETHOST." exit 2 ;; esac fi done ;; *) echo "Cancelling at your request." echo "NO master keys file was replicated." exit 3 ;; esac echo "Endrun." echo "You should acquaint each server with the others (update .ssh/known_hosts2)" echo "by running this on each server:" echo ' for i in isis osiris liberty compton marinduque zamboanga montpellier orsolino; do ssh $i /bin/hostname; done' exit 0