Set up SSH with Sourcetree

Use this page to generate an SSH key using Sourcetree. When you create an SSH key with Sourcetree, you can save the public and private key wherever you want locally. You may want to create an SSH directory when you do, so that you can refer to your SSH keys whenever you need them.

Set up SSH with Sourcetree on Windows

Step 1. Install Sourcetree and add your Bitbucket account

  1. If you don't yet have Sourcetree, go to https://www.sourcetreeapp.com/ and click the Download free button.

  2. Click the .exe file to install Sourcetree. Refer to the Install Sourcetree page for more details.

    1. You may see the Load SSH Key? dialog after installation. Click No if you don't have one and want to use Sourcetree to create one.

  3. Add your account and select SSH as the Preferred Protocol. If you don't connect your account during set up, click Remote to open the Remote repositories page and click Add an account.

Step 2. Create an SSH key

  1. From Tools, select Create or Import SSH Keys.

  2. From the PuTTY Key Generator dialog, click the Generate button.

  3. As the SSH key generates, hover your mouse over the blank area in the dialog. It may take a minute or two.
    When SSH key generation is complete, you see the public key and a few other fields.

  4. Enter a passphrase for your SSH key in the Key passphrase and Confirm passphrase fields.

  5. Click Save public key. From the save dialog, choose where to save your public key, name the file with the .pub file extension, and click Save.

  6. Click Save private key. From the save dialog, choose where to save your private key, name the file, and click Save.

  7. Close the PuTTY Key Generator dialog.

Step 3. Install your private key on Pageant

Sourcetree comes with an SSH authentication agent called Pageant. Load your private key into Pageant to automatically authenticate so that you don't need to enter your passphrase.

  1. Double-click the Pageant (PuTTY Authentication Agent) icon in your system tray to open the Pageant Key List dialog.

  2. Click the Add Key button to open the Select Private Key File dialog.

  3. Navigate to the private key file you saved in Step 1 and click Open.

  4. Enter the passphrase for your SSH key and click OK.
    Pageant shows your key in the running list.

  5. Click Close.

Step 4. Add the public key to your Account settings

  1. From Sourcetree, open the PuTTY Key Generator dialog by going to Tools > Create or Import SSH Keys.

  2. 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.

  3. Enter your passphrase for the SSH key and click OK.

  4. Copy the public key in the first field.

  5. From Bitbucket, select the Settings cog on the top navigation bar.

  6. Select Personal Bitbucket settings from the Settings dropdown menu.
    The Account settings page opens.

  7. Select SSH keys.
    If you've already added keys, you'll see them on this page.

  8. Select Add key.

  9. Enter a Label for your new key, for example, Default public key.

  10. Paste the copied public key into the SSH Key field.

  11. Click Save.
    Bitbucket sends you an email to confirm the addition of the key.

Now that you've got an SSH key set up, use the SSH URL the next time you clone a repository. If you already have a repository that you cloned over HTTPS, change the remote URL for your repository to its SSH URL.

Edit an SSH key

After you add a key, you can edit the key's Label but not the key itself. To change the key's contents, you need to delete and re-add the key.

Set up SSH with Sourcetree on macOS

When you create an SSH key with Sourcetree on macOS, you can only create one key. You'll need to use the command line if you want additional keys.

Step 1. Install Sourcetree and add your Bitbucket account

  1. If you don't yet have Sourcetree, go to https://www.sourcetreeapp.com/ and click the Download free button.

  2. Open the ZIP file to install Sourcetree. Refer to the Install Sourcetree page for more details.

  3. If you don't connect your account during set up, you can add it from the Accounts tab by selecting Preferences from the Sourcetree menu.

Step 2. Create an SSH key

Follow these steps if you don't already have an SSH key for an account. If you do have an SSH key and you want to generate another key, you'll have to use the terminal because you can't use Sourcetree to create a second key.

Creating an SSH key looks something like this:

  1. From the Sourcetree menu, select Preferences.

  2. Click the Accounts tab, select the account where you want to add the SSH key and click Edit.

  3. Change the Protocol to SSH if it's not already selected.

  4. Hold down the OPTION key on your keyboard to see the Generate Key button.

    If you've already generated an SSH key for this account from Sourcetree, the OPTION key won't do anything. Use your existing key or generate another key from the terminal.

  5. Click Generate Key.

  6. Enter a passphrase for the SSH key in the Passphrase and Confirm Passphrase fields.

  7. Click Create.

Step 3. Add the public key to your Account settings

  1. From Bitbucket, select the Settings cog on the top navigation bar.

  2. Select Personal Bitbucket settings from the Settings dropdown menu.
    The Account settings page opens.

  3. Click SSH keys.
    If you've already added keys, you'll see them on this page.

  4. Select your account from your Accounts tab in Sourcetree.

  5. Click the Copy to Clipboard button to copy your public SSH key.

  6. From Bitbucket, click Add key.

  7. Enter a Label for your new key, for example, Default public key.

  8. Paste the copied public key into the SSH Key field.

  9. Click Save.
    Bitbucket sends you an email to confirm the addition of the key.

Now that you've got an SSH key set up, use the SSH URL the next time you clone a repository. If you already have a repository that you cloned over HTTPS, change the remote URL for your repository to its SSH URL.

Edit an SSH key

After you add a key, you can edit the key's Label but not the key itself. To change the key's contents, you need to delete and re-add the key.

Still need help?

The Atlassian Community is here for you.