Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unable to get SSH keys working between sourcetree and github

I was able to create a key and connect to github following these instructions via the command prompt successfully:

https://help.github.com/articles/generating-ssh-keys

However, when I try to connect via Sourcetree and putty I cannot. I've tried:

  1. generating a new key with the putty key generator (SSH-2 RSA)
  2. entering a passphrase
  3. saving the private key
  4. saving the public key and adding a .pub extension
  5. copying/pasting the key from the putty key generator window into github
  6. attemping to refresh branches on a pull from my private github repository from my local repo using the SSH clone URL I got from github

I also tried opening the key generated from the github command line instructions and it wanted me to convert it to a putty-type key which I did and saved off, tried with that one. Also no luck.

What am I doing wrong?

like image 651
turbo2oh Avatar asked Dec 17 '13 20:12

turbo2oh


People also ask

How do I add a SSH key from GitHub to SourceTree?

From Sourcetree, open the PuTTY Key Generator dialog by going to Tools > Create or Import SSH Keys. Click Load, navigate to your SSH folder, and click the private key. Make sure you're looking at All files if you don't see your private key. Enter your passphrase for the SSH key and click OK.

Why is SSH key not working?

Make sure the authorized_keys file and the private key itself have the correct permissions and ownership. Check that key-based authentication is allowed by the server. Make sure the private key is readable by the SSH client. If you're using PuTTY, make sure your SSH keys are properly configured for the session.

How do I fix my SSH key in GitHub?

In terminal enter this command with your ssh file name pbcopy < ~/. ssh/id_rsa. pub This will copy the file to your clipboard Now open you github account Go to Settings > SSH and GPG keys > New SSH key Enter title and paste the key from clipboard and save it. Voila you're done.


2 Answers

In order to get it worked I ended up going to Tools -> Options -> SSH Client and changing it to OpenSSH. I generated and uploaded several different types of keys trying to get it work as well but I think this is what finally did it.

like image 154
turbo2oh Avatar answered Oct 21 '22 01:10

turbo2oh


In my case, I needed to switch to a git or ssh based repo path rather than the https based repo path. This causes SourceTree to switch to SSH based authentication.

This setting can be found at Repository => Repository setting => Paths

Example:

Correct repo paths

[email protected]:<username>/<reponame>.git 

or

ssh://[email protected]/<username>/<reponame>.git 

(Note: if you are working with a repo that isn't yours, replace username with organization name)

Wrong repo path

https://github.com/<username>/<reponame>.git 

HTTPS repo paths result in SourceTree trying to be extra smart and failing spectacularly. You get prompted for a username/password GUI dialog which will never work if you have 2 factor authentication enabled.

like image 28
DeepSpace101 Avatar answered Oct 21 '22 03:10

DeepSpace101