Created
June 22, 2018 22:00
-
-
Save slumos/a5fca4bafa7628601eb79b0359e3ae19 to your computer and use it in GitHub Desktop.
reset known_hosts entry for a hostname
This file contains 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
#! /usr/bin/env zsh | |
if [[ $# != 1 ]]; then | |
print Usage: kh-reset hostname | |
exit 1 | |
fi | |
# Expand the different hostnames and IP | |
if [ -x /usr/bin/dscl ]; then | |
# macOS | |
hosts="$hosts $(dscl . read /Hosts/$1 | awk '/^IPAddress/ { print $2 }')" | |
else | |
# sanity | |
hosts="$1 $(getent hosts $1)" | |
fi | |
# Remove all matching entries from known_hosts | |
for h in ${=hosts}; do ssh-keygen -R $h >& /dev/null; done | |
# Grab the new key into known_hosts | |
ssh-keyscan -tdsa,rsa ${=hosts} >> $HOME/.ssh/known_hosts 2>/dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment