SourceTree on Windows can't connect to GitHub using OpenSSH

(Running Windows 7, SourceTree 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
 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, it doesn't work.

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


2 answers

1 accepted

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.

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

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

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

1 vote

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
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 1
    Host defaultid
     IdentityFile ~/.ssh/id_rsa
    ## Sample 2
    Host customid
     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 command
git clone

# will become
git clone git@defaultid:accountname/reponame.git

## Sample 2
# original command 
git clone

# will become
git 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 and/or 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 -l
2048 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/customid
Enter passphrase for /Users/user/Downloads/customid:
Identity added: /Users/user/Downloads/customid (/Users/user/Downloads/customid)

Kind regards,

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.

Those don't look like Windows instructions.

Suggest an answer

Log in or Join to answer
Community showcase
Brian Ganninger
Published Jan 23, 2018 in Sourcetree

Tip from the team: workflow and keyboard shortcuts

Supported Platforms macOS Sourcetree has a lot to offer and, like many developer tools, finding and using it all can be a challenge, especially for a new user. Everyone might not love ...

273 views 0 3
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot