Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
ssh config key selection issues

Example .ssh/config file:

# severals rules that depend on the wildcard rule at the bottom

    User foo
    IdentityFile /path/to/id-1

Host *
    User bar
    IdentityFile /path/to/id-2
    IdentityOnly yes

Then if you try:

ssh -Tv

It will try id-2 because of the way IdentityFile works. As in the docs:


     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

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 rule. The solution was to explicitly exclude from the wildcard rule, like this:

Host * !
    User bar
    IdentityFile /path/to/id-2
    IdentityOnly yes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment