Skip to content

Instantly share code, notes, and snippets.

@antonydenyer
Created May 31, 2018 10:16
Show Gist options
  • Save antonydenyer/e5682bb53fd62d3fbe11958b184add78 to your computer and use it in GitHub Desktop.
Save antonydenyer/e5682bb53fd62d3fbe11958b184add78 to your computer and use it in GitHub Desktop.
#!/bin/sh
set -e
echo "Updating known host for $1 ..."
KEY=$(ssh-keyscan -t ecdsa-sha2-nistp256 $1 2> /dev/null)
if grep -q $1 ~/.ssh/known_hosts;
then
ESCAPED_KEY=${KEY//\//\\\/}
sed -i "" "s/$1.*$/$ESCAPED_KEY/g" ~/.ssh/known_hosts
echo "updated $1 to $ESCAPED_KEY"
else
echo $KEY >> ~/.ssh/known_hosts
echo "added $1 and set to $KEY"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment