Equivalent of ‘ssh’ config option in Hg for Git?

Posted on


On Windows 7, my .hgrc config file provides a nice an easy way to tell Mercurial about the private SSH key location with the following syntax:

username = John Doe <jdoe@example.com>
ssh = plink.exe -i "C:Usersjdoemykeys.ppk" 

Does anyone knows what is the equivalent syntax for the .gitconfig file? All I can find so far is the GIT_SSH environment variable that does not seem to let me specify the private key location.


If you want to specify a key to be used for all connections, there are two ways to do it with PuTTY:

  1. Load the key into Pageant, the SSH agent program. Just double-click the .ppk file and enter its passphrase, if any.

    This has several advantages: you can encrypt the key on disk and still retain the convenience of password-less logins, and you can have multiple keys loaded and they all will be tried.

    (The OpenSSH equivalent of Pageant is ssh-agent, by the way.)

  2. Edit PuTTY’s default configuration to point to the key. Open a new PuTTY window, go to Connection → SSH → Auth, and choose your key file under Private key file. Go back to Session, click the “Default Settings” item, and click Save.

    plink uses the same session settings as PuTTY, and will automatically use the key you configured here.

    (In OpenSSH, you would edit ~/.ssh/config to achieve the same result.)

Leave a Reply

Your email address will not be published. Required fields are marked *