Re: Use different ssh keys for different github repos (per-url sshCommand)
- From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
- Date
- Jul 19, 2018, 12:50 UTC
- Message-ID
- <87zhynbd9z.fsf@evledraar.gmail.com>
- In-Reply-To
- <44d3c280-3fb2-2415-46b7-343983e76e0b@gmail.com>
On Thu, Jul 19 2018, Basin Ilya wrote:
Show 22 quoted lines
> Hi. > > I have two github accounts, one is for my organization and I want git to automatically choose the correct ssh `IdentityFile` based on the clone URL: > > git@github.com:other/publicrepo.git > ~/.ssh/id_rsa > git@github.com:theorganization/privaterepo.git > ~/.ssh/id_rsa.theorganization > > Unfortunately, both URLs have same host name, therefore I can't configure this in the ssh client config. I could create a host alias there, but sometimes somebody else gives me the github URL and I want it to work out of the box. > > I thought I could add a per-URL `core` section similar to `user` and `http`, but this section is ignored by git (2.18): > > [core "git@github.com:theorganization"] > sshCommand = /bin/false > #sshCommand = ssh -i ~/.ssh/id_rsa.theorganization > > I thought of writing a wrapper script to deduce the key from the arguments: > > git@github.com git-upload-pack '/theorganization/privaterepo.git' > > Is this the only option?
Yes, I had a similar problem a while ago (which I sent an RFC patch for) which shows a script you can use: https://public-inbox.org/git/20180103102840.27897-1-avarab@gmail.com/
It would be nice if this were configurable. Instead of the way you suggested, it would be more general if we supported:
[Include "remote:git@github.com:theorganization*"]
path = theorganization.configAlthough I'm sure we'd have some interesting chicken & egg problems there when it comes to bootstrapping the config parsing.