0

I have multiple git repo (Client1, Client2, personal).

I did configured the profiles as suggested here.

https://medium.com/@trionkidnapper/ssh-keys-with-multiple-github-accounts-c67db56f191e

Now my config file have 3 different profiles.

Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_personal

Host gitlab.client1.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_client_a

Host github.com/client2.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_client_b

Till yesterday everything is fine, whenever I do git pull or push for client_a corresponding IdentityFile is using for the changes to pull or push.

Today When I tried to do git pull on client b repo ~/.ssh/id_rsa_personal is going to be used instead of ~/.ssh/id_rsa_client_b and it's failing as it is not the intended one(permission issue). Not sure how to point to ~/.ssh/id_rsa_client_b instead of ~/.ssh/id_rsa_personal.

Any thoughts?

data_addict
  • 816
  • 3
  • 15
  • 32
  • 2
    I think [this question](https://stackoverflow.com/q/14689788/243245) explains the problem: I don't think `github.com/client2.com` works, I think you need to make a ficticious host `Host client2.github.com` and then use that in your remote URLs. – Rup Jul 01 '19 at 08:54
  • @Rup, tried client2.github.com this one, no luck – data_addict Jul 01 '19 at 08:58
  • 1
    @user805 I faced the same problem a few times ago, and ended developping my own tool for this purpose: a `sudo` like layer for operations that need authentication, such as `fetch`, `pull`, `push` :-) You can find it here: https://github.com/yannoff/su-git – Yannoff Jul 01 '19 at 09:09

1 Answers1

2

As Rup says in the comments, change the Host to something shorter like Host client2 (this is just for convenience), add IdentitiesOnly yes to each host so that it only offers the specified file, and make the remote URL something like git@client2:yourrepo.git.

neoto
  • 359
  • 1
  • 7