Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
setup_ssh.sh - copies SSH public keys between hosts
#!/bin/bash
HOST=0
if [ "$SYSTEM" == "type1" ]; then
HOST=192.168.0.2
elif [ "$SYSTEM" == "type2" ]; then
HOST=192.168.0.1
else
echo "Error 1"
exit
fi
LOG_FILE=/root/setup_ssh.log
SSH_PATH=/root/.ssh
SSH_KEY=${SSH_PATH}/id_rsa
SSH_PUB=${SSH_PATH}/id_rsa.pub
if [ ! -f ${SSH_KEY} ]; then
ssh-keygen -f ${SSH_KEY} -N "" >> ${LOG_FILE} 2>&1
fi
echo "If asked, enter the Scorpion2 password, if not asked, keys already exchanged..."
cat ${SSH_PUB} | ssh ${HOST} -o StrictHostKeyChecking=no "mkdir -p ${SSH_PATH} && cat >> ${SSH_PATH}/authorized_keys"
echo "Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment