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?
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!!.
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
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 "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
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
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 firstname.lastname@example.org:email@example.com:your_username/ProjectName.git
Cloning into 'YourProject'...
The authenticity of host 'github.com (18.104.22.168)' 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,22.214.171.124' (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!!!
Supported Platforms macOS Windows We recently introduced support for additional hosting services such as GitHub Enterprise, GitLab (Cloud, Community Edition, Enterprise Edition), and...
Connect with like-minded Atlassian users at free events near you!Find an event
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.Host an event
You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events