Skip to content

Instantly share code, notes, and snippets.

@janmoesen
Created October 23, 2013 08:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save janmoesen/7114384 to your computer and use it in GitHub Desktop.
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.
# 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