#! /bin/bash ############################ # Launch this script as a current $user in the current node $cn to configure passwordless ssh to-and-fro $cn and the remote node $rn for the $user who execute this script. # Assumption: The $user has already existed in the $rn and $cn nodes. # The default values for $cn, $rn, $user are defined as cn=10.192.1.10 rn=10.192.1.21 userhome=$(echo $HOME) user=$(echo $USER) ############################ #### Modify the following variables, $cn, $rn to suit your case cn=10.192.1.10 ### ur current node IP rn=10.192.1.21 ### the IP for remote node #### end of Modify the following variables, $cn, $rn and $user to suit your case #1a ## generates two files, id_rsa and id_rsa.pub, in /share/home/$user/.ssh in the current compute node if [[ -e $userhome/.ssh/id_rsa.pub ]]; then echo "pub rsa exists. Will not creat any."; else ssh-keygen -t rsa; fi ### 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 $userhome/.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"