Example .ssh/config
file:
# severals rules that depend on the wildcard rule at the bottom
Host foo.com
HostName foo.com
User foo
IdentityFile /path/to/id-1
Host *
User bar
IdentityFile /path/to/id-2
IdentityOnly yes
Then if you try:
ssh -Tv git@foo.com
It will try id-2
because of the way IdentityFile
works. As in the docs:
IdentityFile
[...]
It is possible to have multiple identity files specified in configu‐
ration files; all these identities will be tried in sequence. Mul‐
tiple IdentityFile directives will add to the list of identities
tried (this behaviour differs from that of other configuration
directives).
Although it doesn't specify which order it follows when deciding which key to use, it always
tried my wildcard rule key first, even if I moved it to before my foo.com
rule. The
solution was to explicitly exclude foo.com
from the wildcard rule, like this:
Host * !foo.com
User bar
IdentityFile /path/to/id-2
IdentityOnly yes