I'm having a hard time finding proper docs on the order in which the OpenSSH client tries private keys for authenticating against a server, given that all of the following are present:
- key files with default names in
~/.ssh
, e.g.~/.ssh/id_rsa
, - key files with non-default names that are configured to be used with a specific host via
~/.ssh/config
, - keys managed by
ssh-agent
.
Are all of these locations always tried (provided that the host matches an entry in ~/.ssh/config
), and in which order?
Background: I have ~/.ssh/id_rsa
which can only be used to authenticate against server A, and I have another key managed by ssh-agent
that can only be used to authenticate against server B. When trying to ssh
to B, authentications fails, apparently because only ~/.ssh/id_rsa
is tried. There does not seem to be a fallback to try the key managed by ssh-agent
.