0

I want to configure my SSH client to work with different keys when pushing to GitHub, with one key being the "default".

I thought that putting this into .ssh/config will give me what I need:

Host github-foo
    HostName github.com
    IdentityFile ~/.ssh/id_rsa_FOO

Host *
    IdentityFile ~/.ssh/id_rsa_BAR

according to man ssh_config, when git is connecting to a remote with url git@github-foo:myuser/myproject, ssh should take the first value of IdentityFile form matching Host blocks (~/.ssh/id_rsa_FOO in this case) and use it. However, ssh is authenticating with the id_rsa_BAR key. What am I doing wrong? Is this a bug?

I've read this, but that solution requires changing every remote repo url; there is no "default" key in that approach. I would like to be able to leave the url unchanged for all repos that should use the "default" key (id_rsa_BAR in this example).

2

1 Answer 1

0

I'm not sure what OS you're using, but I'm able to use multiple keys by using an SSH Key Agent. I'm running Windows and using pageant. I'd probably start with https://gist.github.com/tobalsan/4008409 . I'm sure you can get an agent running for your OS.

Hope this helps.

2
  • Thanks for the gist, but it shows the approach I already know - i.e. defining separate ssh host aliases for each key. This requires using a custom url in all repos. I wanted to have a smarter solution, but I guess it's not possible. Sep 16, 2017 at 13:17
  • I see now. Have you tried putting the Host * at the top of your config? May 4, 2018 at 17:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .