Skip to content

Instantly share code, notes, and snippets.

@greg-1-anderson
Last active September 7, 2016 21:52
Show Gist options
  • Save greg-1-anderson/99db95048bcbb7580a9fdb73cc5ad629 to your computer and use it in GitHub Desktop.
Save greg-1-anderson/99db95048bcbb7580a9fdb73cc5ad629 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Add the ssh key for the specified Pantheon site and environment
# to the user's known_hosts file.
#
# See: http://serverfault.com/questions/132970/can-i-automatically-add-a-new-host-to-known-hosts
#
# Note that this script does not remove and re-add the ssh keys;
# if you want to do that, you might as well just use -o StrictHostKeyChecking=no.
#
SITE="$1"
ENV="$2"
SITE_ID=$(terminus site info --site="$SITE" --field=id)
grep -q appserver.$ENV.$SITE_ID.drush.in ~/.ssh/known_hosts
if [ $? == 0 ]
then
echo "appserver.$ENV.$SITE_ID.drush.in already known"
exit 0
fi
ssh-keyscan -p 2222 appserver.$ENV.$SITE_ID.drush.in >> ~/.ssh/known_hosts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment