0

macOS Sierra 10.12.4, OpenSSH_7.4p1, LibreSSL 2.5.0.

My ssh config file is setup as follows (just one of the servers):

Host github
    Hostname            github.com
    HostKeyAlias        github
    User                git
    IdentityFile        /Users/abhay/.ssh/github
    IdentitiesOnly      yes

When I use ssh github at the command line, it works without problem, the correct identity file is used and I'm able to log in.

But if I use ssh [email protected], the config is ignored, and my default identity file id_rsa is used instead. This is true for other servers too, not just github.

Is this how it is supposed to work? Sometimes I forget the alias or just prefer to login with complete user@server but then ssh fails.

How to resolve this?

1 Answer 1

2

Yes, that is supposed to work like that.

You can easily overcome this by changing the first line to

Host github github.com

The reason is that all configurations you do for a Host entry are matched to the hostname you give on the command line, and only apply for this name. This makes it possible to have multiple configurations for the same hostname, e.g. with different keys. If there is no match, the default config is used.

1
  • Thank you. That works. Also it works if I add the private key identities to the authentication agent: $ ssh-add ~/.ssh/github Commented Apr 23, 2017 at 0:49

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.