#! /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}') ## 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)) if [[ -e /home/$username/.ssh/id_rsa.pub ]]; then echo pub rsa exists. Will not create any.; else echo to generate ssh keys; ssh-keyscan 192.168.1.10 >> /home/$username/.ssh/known_hosts; coc-gen_sshkeygen; fi echo ' ' /share/apps/local/bin/coc-sshreachable hosts=$(cat /share/tmp/ssh-reachable.dat) echo 'hosts=' $hosts for rn in $hosts do 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" #sshpass -p $TMP_PASS ssh -oStrictHostKeyChecking=no $rn "/share/apps/local/bin/gen_bashrc.txt" #echo Have done gen_bashrc in $rn # echo 'see me 0?' # echo ' ' ip='192.168.1.10' # ssh-keygen -R $ip # echo 'see me 1' # ssh-keygen -R $rn echo 'see me 2' # ssh-keyscan -H $ip >> /home/$username/.ssh/known_hosts echo 'see me 3' ssh-keyscan -H $rn >> /home/$username/.ssh/known_hosts echo 'see me 4' done ############################ #username=$(cat /share/apps/configrepo/users_data/newuser.dat | awk '{print $2}') #passwd=$(cat /share/apps/configrepo/users_data/newuser.dat | awk '{print $4}') #mkdir /share/$username #chmod -R 755 /share/$username #chown -R $username:users /share/$username