SourceTree on Windows can't connect to GitHub using OpenSSH
Asked by Nitzan Shaked:

(Running Windows 7, SourceTree 1.5.1.0 configured to use OpenSSH)

When my private key (stored in `C:\Users\MyUser\.ssh`) is called `id_rsa` everything works fine: I can clone GitHub repositories, pull, etc., using regular GitHub URLs: git@github:my-github-user/my-repo.git.

But when I rename my private key to something else and let SourceTree know about this (under Tools -\> Options -\> SSH Key) it fails to connect.

Furthermore: if I create `C:\Users\MyUser\.ssh\config` and add something like

    Host github2

     Hostname github.com

     User git

     IdentityFile something_else 

And try URLs such as git@github2:my-github-user/my-repo.git or [ssh://github2/my-github-user/my-repo.git](ssh://github2/my-github-user/my-repo.git,), it doesn't work.

It's as if OpenSSH in SourceTree is hardwired to read only `id_rsa`and ignore other settings (such as .ssh\\config and/or SSH Key).

Ideas?


Answers:
author: Seth
body: I am using a private key other than id_rsa, but my configuration is completely different than yours.

First of all, I am not using .ssh to store my key or for any manual config.

Secondly, I am not specifying a specific key in SourceTree options.

Thirdly, I am using Pageant as my key agent, which I DO have set in my SourceTree config. I have Pageant configured to load the key at startup. It seems that SourceTree simply tries to authenticate with any keys in Pageant.

comments: author: Seth
body: Also, Rafael's instructions seem tailored for Mac/Linux, which isn't going to be particularly helpful since you said you're on Windows.


author: Nitzan Shaked
body: That's interesting, I'll check it out. I was still hoping to understand why OpenSSH (no agent) doesn't work, though.


author: Nitzan Shaked
body: Well it works. Unfortunate that I couldn't find any other solution, but for the sake of good order I'll accept this answer.


author: rsperafico
body: Hi Nitzan,

**Create a SSH config file**

When you have multiple identity files or a ssh key different from id_rsa, create a SSH config file mechanisms to create aliases for your various identities. You can construct a SSH config file using many parameters and different approaches. The format for the alias entries use in this example is:

Host **alias**   
HostName **[bitbucket.org](http://bitbucket.org)**   
IdentityFile **\~/.ssh/identity**

To create a config file for one identity different from id_rsa or two identities+ (workid and personalid), you would do the following:

1. Open a terminal window.
2. Edit the \~/.ssh/config file.   
   If you dont have a *config* file, create one.
3. Add an alias for each identity combination for example:  

   ```
   ## Sample 1Host defaultid HostName bitbucket.org IdentityFile ~/.ssh/id_rsa## Sample 2Host customid HostName bitbucket.org IdentityFile /Users/user/Downloads/customid
   ```

4. Close and save the file.

Now, you can substitute the alias for portions of the repository URL address as illustrated below:

```
## Sample 1# original commandgit clone git@bitbucket.org:accountname/reponame.git# will becomegit clone git@defaultid:accountname/reponame.git## Sample 2# original command git clone git@bitbucket.org:accountname/reponame.git# will becomegit clone git@customid:accountname/reponame.git
```

**Load each key into the appropriate Git account**

You load each identities public key into corresponding account by copying *id_rsa.pub* and/or *customid.pub* content and paste it into individual SSH key fields (Deployment keys).

**Ensure the ssh-agent is loaded with your keys**

List the currently loaded keys:

```
$ ssh-add -l2048 32:ad:d1:3c:4b:3b:f4:34:7a:c5:b2:4a:be:8e:d8:9a /Users/user/.ssh/customid (RSA)2048 68:ef:d6:1e:4b:3b:a3:52:6f:b0:c3:4b:da:e8:d1:9f /Users/user/Downloads/customid (RSA)
```

If necessary, add your new key to the list:

```
$ ssh-add /Users/user/Downloads/customidEnter passphrase for /Users/user/Downloads/customid:Identity added: /Users/user/Downloads/customid (/Users/user/Downloads/customid)
```

Kind regards,  
Rafael

comments: author: Nitzan Shaked
body: Rafael -- kindly \*reread\* my question. You'll notice I did just that, but to no avail. I also made a specific comment re ssh-agent.


author: Seth
body: Those don't look like Windows instructions.