In Mercurial, I can specify the command (and thus the certificate) used for SSH per-repository in .hg/hgrc, for example:
[ui]
...
ssh = "C:\path\to\ssh.exe" -i "C:\Development\Identities\identity1.id_rsa"
Most instructions I can find on configuring Git seem to use the bundled ssh.exe to manage the certificates, for example GitHub's guide for Windows. There is a way of specifying a script for Git to use for SSL (here under "No supported authentication methods available") via an environment variable, but that per user and not granular enough for me.
How can I specify a per-repository SSH command line in Git?
I'm unaware of a way to make git do this. But ssh should be flexible enough to do it instead.
First note that you can specify more than one identity file. It will try multiple identities in turn, until one is accepted.
Second, under unix, if you want only certain identities to be tried for certain hosts, you can do so by modifying ~/.ssh/config to have stanzas such as:
Host <hostname>
IdentitiesOnly yes
IdentityFile "C:\Development\Identities\identity1.id_rsa"
Though I don't know if that will work for your bundled windows ssh client, or where the config file goes, if it does.
EDIT: if you want to use two different identities on the same host, that can be done too:
Host <alias1>
HostName <realhostname>
IdentiesOnly yes
IdentityFile identity1
Host <alias2>
HostName <realhostname>
IdentiesOnly yes
IdentityFile identity2
and use and as the hosts in git (there is substantial support to treat one host as another, or do even stronger rewriting with config options such as url.<base>.insteadOf.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With