#! /bin/bash # Launch this script as $user in the frontend to configure passwordless ssh to-and-fro the frontend and all 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) #1a if [[ -e $userhome/.ssh/id_rsa.pub ]]; then echo "pub rsa exists. Will not creat any."; else ssh-keygen -t rsa; fi HOSTNAME=$(cat /etc/hostname) hosts=$(cat /etc/hosts | grep 192 | awk {'print $1}') 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 current compute node. ssh $user@$rn "ssh-copy-id -i $userhome/.ssh/id_rsa.pub $HOSTNAME" done