Last active
November 11, 2024 01:25
-
-
Save xxorax/e46341cf57fad0bdd80a 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 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