-
-
Save 54keesh/648fc9c9c675d7cd23471c6aa50b42ed to your computer and use it in GitHub Desktop.
Unhash the hostnames hashed in your known_hosts file by passing their names.
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/bash | |
# based on http://unix.stackexchange.com/questions/175071/how-to-decrypt-hostnames-of-a-crypted-ssh-known-hosts-with-a-list-of-the-hostna/175199#175199 | |
function replace { | |
host="$1" | |
found=$(ssh-keygen -F "$host" 2>/dev/null | grep -v '^#' | sed "s/^[^ ]*/$host/") | |
if [ -n "$found" ]; then | |
ssh-keygen -R "$host" &>/dev/null | |
echo "$found" >>~/.ssh/known_hosts | |
echo "Found and replaced: $host" | |
else | |
echo "Not found: $host" | |
fi | |
} | |
if [ "$#" -eq 0 ]; then | |
echo "Enter one hostname per line, or input a filename ( < file )." | |
while read host comment; do | |
replace "$host" | |
done | |
exit | |
fi | |
while (( "$#" )); do | |
replace "$1" | |
shift | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment