mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Sitaram Chamarty <>
To: Basin Ilya <>
Subject: Re: Use different ssh keys for different github repos (per-url sshCommand)
Date: Thu, 19 Jul 2018 18:52:47 +0530	[thread overview]
Message-ID: <> (raw)
In-Reply-To: <>

On Thu, Jul 19, 2018 at 03:24:54PM +0300, Basin Ilya wrote:
> 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:
>        ~/.ssh/id_rsa
>        ~/.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 ""]
>         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-upload-pack '/theorganization/privaterepo.git'
> Is this the only option?

This is what I do (I don't have two accounts on github, but
elsewhere; same idea though)

    # this goes in ~/.ssh/config

    host gh1
        user                git
        identityfile        ~/.ssh/id_rsa_1

    host gh2
        user                git
        identityfile        ~/.ssh/id_rsa_2

Now use "gh1:username/reponame" and "gh2:username/reponame" as
URLs.  It all just works.

  parent reply	other threads:[~2018-07-19 13:22 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-19 12:24 Use different ssh keys for different github repos (per-url sshCommand) Basin Ilya
2018-07-19 12:50 ` Ævar Arnfjörð Bjarmason
2018-07-19 16:47   ` Jeff King
2018-07-19 13:22 ` Sitaram Chamarty [this message]
2018-07-19 13:27   ` Sitaram Chamarty
2018-07-19 16:42 ` Jeff King
2018-07-19 19:01   ` Basin Ilya

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

  List information:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).