#! /bin/bash # Launch this script as root from the frontend to set up passwordless ssh to-and-fro the frontend and all other nodes in the cluster for the user as specified in /share/apps/configrepo/users_data/newuser.dat TMP_PASS=$(cat /share/apps/configrepo/users_data/newuser.dat | awk '{print $4}') username=$(cat /share/apps/configrepo/users_data/newuser.dat | awk '{print $2}') uid=$(cat /share/apps/configrepo/users_data/newuser.dat | awk '{print $3}') echo to remove /home/$username/.ssh rm -rf /home/$username/.ssh ## Generate two files, id_rsa and id_rsa.pub, in /home/$username/.ssh in the current compute node echo 1. Generate two files, id_rsa and id_rsa.pub, in /home/$username/.ssh in the current compute node $(echo $(hostname)) echo to generate ssh keys coc-gen_sshkeygen ssh-keyscan 192.168.1.10 >> /home/$username/.ssh/known_hosts chown $username:users /home/$username/.ssh/known_hosts /share/apps/local/bin/coc-sshreachable hosts=$(cat /share/tmp/ssh-reachable.dat) echo 'hosts=' $hosts #hosts=c21 for rn in $hosts do echo 'rn=' $rn echo 2. Copy the rsa key of $username in the current node $HOSTNAME to the remote node $rn. Password is $TMP_PASS sshpass -p $TMP_PASS ssh-copy-id -i /home/$username/.ssh/id_rsa.pub -o StrictHostKeyChecking=no $username@$rn echo ' ' echo 3. Remotely generates the rsa key of the user $username in the remote node $rn by ssh-ing from the current node $HOSTNAME sshpass -p $TMP_PASS ssh -oStrictHostKeyChecking=no $rn "if [[ -e /home/$username/.ssh/id_rsa.pub ]] ; then echo Will not generate id_rsa.pub; else ssh-keyscan 192.168.1.10 >> /home/$username/.ssh/known_hosts; yes '' | coc-gen_sshkeygen ; fi" echo ' ' echo 4. Remotely ssh-copy-id from the remote node $rn to the frontend sshpass -p $TMP_PASS ssh -oStrictHostKeyChecking=no $rn "sshpass -p $TMP_PASS ssh-copy-id -i /home/$username/.ssh/id_rsa.pub -oStrictHostKeyChecking=no $username@192.168.1.10" ssh-keyscan -H $rn >> /home/$username/.ssh/known_hosts done