Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,559,535
Community Members
 
Community Events
184
Community Groups

Having Trouble Creating SSH Key And Connecting To GitHub On Mac

Edited

Hello, 

I've been struggling to create an SSH key in SourceTree on Mac, and have it successfully connect to my GitHub repo. I try to add my account and click on the "Generate SSH Key" option, and that works fine. But, then it gives me an error saying that the SSH key failed to upload to GitHub and that I should manually add the SSH Key. Ok... So I do that and copy and paste the public key from Sourcetree into GitHub, but then, when I try to clone my repo, I get infinitely stuck on the spinning wheel while my remote is loading. How can I set up SSH keys with Sourcetree and Github on Mac?

3 answers

1 accepted

6 votes
Answer accepted

Hello everybody, 

I have great news. I found a good solution to this problem which I will outline for everybody below. This solution works for authenticating using SSH AND 2-Factor Authentication for SourceTree 4.0.2 on Mac. Now you can have security of SSH and 2-Factor Authentication, and keep using your favorite Git GUI yay!!.

Steps:

1. Open the app called "Keychain Access" on Mac.

2. Search for "git" and delete all the keys you find (assuming you aren't using those keys for any other things)

3. Go to your home folder

cd ~

4. Delete your .ssh folder (ASSUMING YOU AREN'T USING ANY KEYS IN THERE!!)

rm -rf .ssh

5. Create a new SSH Key

ssh-keygen -t ed25519 -C "your_email@example.com"

6. When you're prompted to "Enter a file in which to save the key," press Enter. This accepts the default file location.

7. At the prompt, type a secure passphrase.

> Enter passphrase (empty for no passphrase): [Type a passphrase]
> Enter same passphrase again: [Type passphrase again]

8. Start the ssh-agent in the background.

$ eval "$(ssh-agent -s)"
> Agent pid 59566

9. Check to see if your ~/.ssh/config file exists in the default location.

$ open ~/.ssh/config
> The file /Users/you/.ssh/config does not exist.

10. If the file doesn't exist, create the file.

$ touch ~/.ssh/config

11. Open your ~/.ssh/config file, then modify the file, replacing ~/.ssh/id_ed25519 if you are not using the default location and name for your id_ed25519 key.

Host *
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_ed25519

Note: If you chose not to add a passphrase to your key, you should omit the UseKeychain line.

12. Add your SSH private key to the ssh-agent and store your passphrase in the keychain. If you created your key with a different name, or if you are adding an existing key that has a different name, replace id_ed25519 in the command with the name of your private key file.

$ ssh-add -K ~/.ssh/id_ed25519

13. Add the SSH key to your GitHub account.

14. Go to an empty folder and clone your GitHub repo

git clone git@github.com:your_email@example.com:your_username/ProjectName.git

15.

Cloning into 'YourProject'...

The authenticity of host 'github.com (192.30.255.112)' can't be established.

RSA key fingerprint is SHA256:aaaaabbbbbcccccddddeeee.

Are you sure you want to continue connecting (yes/no/[fingerprint])? yes

Warning: Permanently added 'github.com,192.30.255.112' (RSA) to the list of known hosts.

 16. Open SourceTree and add your account with Auth Type: OAuth, Protocol SSH, then click on "Connect Account". DON'T click on Generate Key, leave that blank.

17. Once you successfully connect, you will see an orange warning icon next to the SSH text. Ignore that, it means nothing.

18. SourceTree will work now with your remotes!!!

Thanks! This fixed the issue for me. Step 14 & 15 was really key to make this work for me. I initially tried cloning the repo through SourceTree but that didn't work. I guess it really needed the known hosts-file that would only get created by cloning via command line.

Like JeffBenusa likes this

Amazing! thank you. I've been fighting this forever. I can't believe that Sourcetree never can get this right

This worked for me as well. Like Eric, steps 14 and 15 are what did it for me. I tried many other things previously (including every other step in this list), and nothing seemed to do the trick until I did those things. Thanks!

you may check the permissions on the ~/.ssh/config file, it needs to be 600.

chmod 600 ~/.ssh/config

I'm stuck on this issue also, but the steps above don't work for me. No matter what I do I get the "must add SSH key manually" error when adding a user account, even after I just added the SSH key I'm using to GitHub. :( been stuck on this for week+ now...

Did you ever find another answer.   I also tried the above approach and it did not solve my problem.  When I try the following it fails:

 

ssh-add -l -E SHA256

The agent has no identities.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events