Created
May 31, 2018 10:16
-
-
Save antonydenyer/e5682bb53fd62d3fbe11958b184add78 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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