#! /bin/bash # Launch this script as $user in the current node to set up passwordless ssh to-and-fro the current node and all other nodes in the cluster for the $user ## Generate two files, id_rsa and id_rsa.pub, in /share/home/$user/.ssh in the current compute node userhome=$(echo $HOME) if [[ -e $userhome/.ssh/id_rsa.pub ]]; then echo "pub rsa exists. Will not creat any."; else ssh-keygen -t rsa; fi frontend=$(cat /etc/hostname) ### this returns the frontend name coc-sshreachable hosts=$(cat /share/tmp/ssh-reachable.dat) for i in $hosts do checkping=$(ping -q -c1 -W 1 $i | awk 'NR==4 {print $4}') if [ $checkping -eq 0 ] then echo $i is not responding to ping after 1 second fi if [ $checkping -eq 1 ] then echo $i is responding to ping within 1 second echo $i >> hosttemp.dat fi done hosts=$(cat hosttemp.dat | uniq) rm -rf hosttemp.dat ### end of script to generate ssh-reachable nodes, $hosts for rn in $hosts do ### 1b copy the rsa key of the $user in the current node to the remote node ssh-copy-id -i $userhome/.ssh/id_rsa.pub $rn ### 2a remotely generates the rsa key for the $user in the rn by ssh-ing from the current compute node. ssh $user@$rn "if [[ -e ~/.ssh/id_rsa.pub ]]; then echo "pub rsa exists. Will not creat any"; else ssh-keygen -t rsa; fi" ### 2b remotely asks the rsa key for the $user in the $rn to be copied via ssh to the node from which this script is launched. ssh $user@$rn "ssh-copy-id -i $userhome/.ssh/id_rsa.pub $frontend" if [ $(whoami) != 'root' ] then ssh $user@$rn "/share/apps/local/bin/gen_bashrc.txt" fi done