Skip to content

Instantly share code, notes, and snippets.

@zapkub
Created November 5, 2018 13:31
Show Gist options
  • Save zapkub/1da1c5edc7cc50becf6408e14e6772e5 to your computer and use it in GitHub Desktop.
Save zapkub/1da1c5edc7cc50becf6408e14e6772e5 to your computer and use it in GitHub Desktop.
Run command shell on remote server and check if password exists then add public key
## BK1 deployment script with SSH
if [ -z "$SSH_DEPLOYMENT_SERVER" ]
then
echo ERROR: please provide SSH_DEPLOYMENT_SERVER variable to deploy instance to server
exit 1
else
echo Deploy BK1 API server instance to $SSH_DEPLOYMENT_SERVER
fi
SSH_PASSWORD_REQUIRED=$(ssh $SSH_DEPLOYMENT_SERVER -qo PasswordAuthentication=no echo 0 || echo 1)
if [ "$SSH_PASSWORD_REQUIRED" == 1 ]
then
echo "PASSWORD REQUIRED... try to write public key to host"
cat ~/.ssh/id_rsa.pub | ssh $SSH_DEPLOYMENT_SERVER 'cat >> ~/.ssh/authorized_keys'
else
echo "PASS..."
fi
## Begin your step below
ssh $SSH_DEPLOYMENT_SERVER ls
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment