Skip to content

Instantly share code, notes, and snippets.

@dotherightthing
Last active February 12, 2020 06:26
Show Gist options
  • Save dotherightthing/d3837b0378595dafb7981f6bbb6b0f43 to your computer and use it in GitHub Desktop.
Save dotherightthing/d3837b0378595dafb7981f6bbb6b0f43 to your computer and use it in GitHub Desktop.
[Setting up SSH to work with Sourcetree] #git #ssh #macos

Setting up SSH to work with Sourcetree

1. Generate a SSH key

Source: https://confluence.atlassian.com/bitbucket/set-up-an-ssh-key-728138079.html

  1. Run SSH key generator: ssh-keygen
  2. Save key to default location (/Users/name/.ssh/id_rsa)
  3. Add a passkey/phrase
  4. Ignore the output which prints to Terminal
  5. Check that the id_rsa (private) and id_rsa.pub (public) keys were generated:
cd ~/.ssh
ls

2. Add the key to the ssh-agent

Source: https://confluence.atlassian.com/bitbucket/set-up-an-ssh-key-728138079.html

  1. Start the agent:
eval `ssh-agent`
  1. Add the private key: ssh-add -K ~/.ssh/id_rsa
  2. Create a config file:
cd ~/.ssh
touch config
nano config

# Enter the following
Host *
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_rsa

Note: I initially missed the UseKeychain step in the Bitbucket instructions. The other lines come from the page that helped me resolve this: Source Tree SSH Public Key Denied .

3. Add the public key to Bitbucket

  1. Copy the public key to the clipboard: pbcopy < ~/.ssh/id_rsa.pub
  2. Log in to https://bitbucket.org/
  3. Click on your avatar
  4. Select Security > SSH Keys
  5. Click Add key
  6. Paste the key and name appropriately

4. Add the public key to Github

  1. Copy the public key to the clipboard: pbcopy < ~/.ssh/id_rsa.pub
  2. Log in to https://github.com/
  3. Click on your avatar
  4. Select Settings
  5. Select SSH and GPG keys
  6. Click New SSH Key
  7. Paste the key and name appropriately

5. Authorise Sourcetree with Bitbucket

Source: https://confluence.atlassian.com/get-started-with-sourcetree/connect-your-bitbucket-or-github-account-847359096.html

  1. Open Sourcetree
  2. Window > Show Repository Browser
  3. Click the gear icon and select Accounts
  4. Add > Host > Bitbucket
  5. Select the defaults of OAuth, SSH, SSH Key: id_rsa.pub
  6. Click Connect Account

6. Authorise Sourcetree with Github

Repeat as for Bitbucket

7. Check that it worked

  1. ssh -Tv [email protected]
  2. Open a private repo page on Bitbucket > click Clone > copy the git clone .. command and run in Terminal
  3. Open a private repo page on Bitbucket > click Clone > Clone in Sourcetree

8. Things to try if it doesn't work

  1. Sourcetree > Git - Preferences > Git > Reset to Embedded Git (already set)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment