Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Override "ssh" to specify IdentityFile based on the host, but not in ~/.ssh/config. See 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);
echo command ssh "${new_args[@]}";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment