Created
October 23, 2013 08:00
-
-
Save janmoesen/7114384 to your computer and use it in GitHub Desktop.
Override "ssh" to specify IdentityFile based on the host, but not in ~/.ssh/config. See http://serverfault.com/questions/450796/how-could-i-stop-ssh-offering-a-wrong-key/450807 for some background. Not really tested. Also, this is very naive and assumes your host does not appear in the other arguments.
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
# A wrapper for "ssh" to avoid having multiple keys sent. Leave the | |
# IdentityFile options out of your host sections in ~/.ssh/config. This | |
# function adds them based on the arguments. | |
function ssh { | |
local new_args=(); | |
local arg; | |
for arg; do | |
if [ "$arg" = 'purplepixelhost' ]; then | |
new_args+=(-i ~/.ssh/purplepixelhost.id_rsa); | |
elif [ "$arg" = 'qiwib0xorz' ]; then | |
new_args+=(-i ~/.ssh/matthias.id_rsa); | |
fi; | |
new_args+=("$arg"); | |
done; | |
echo command ssh "${new_args[@]}"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment