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
If you don't yet have Sourcetree, go tohttps://www.sourcetreeapp.com/ and click theDownload free button.
Click the
.exefile to install Sourcetree. Refer to theInstall Sourcetree page for more details.You may see the Load SSH Key? dialog after installation. ClickNo if you don't have one and want to use Sourcetree to create one.
Add your account and selectSSH as thePreferred Protocol. If you don't connect your account during set up, clickRemote to open theRemote repositories page and clickAdd an account.
Step 2. Create an SSH key
FromTools, selectCreate or Import SSH Keys.
From thePuTTY Key Generator dialog, click theGenerate button.
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.Enter a passphrase for your SSH key in theKey passphrase andConfirm passphrase fields.
ClickSave public key. From the save dialog, choose where to save your public key, name the file with the
.pubfile extension, and clickSave.ClickSave private key. From the save dialog, choose where to save your private key, name the file, and clickSave.
Close thePuTTY 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.
Double-click thePageant (PuTTY Authentication Agent) icon in your system tray to open thePageant Key List dialog.
Click theAdd Key button to open theSelect Private Key File dialog.
Navigate to the private key file you saved in Step 1 and clickOpen.
Enter the passphrase for your SSH key and clickOK.
Pageant shows your key in the running list.Click Close.
Step 4. Add the public key to your Account settings
From Sourcetree, open thePuTTY Key Generator dialog by going toTools > Create or Import SSH Keys.
ClickLoad, 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 clickOK.
Copy the public key in the first field.
From Bitbucket, select theSettingscog on the top navigation bar.
SelectPersonal Bitbucket settingsfrom theSettingsdropdown menu.
The Account settings page opens.Select SSH keys.
If you've already added keys, you'll see them on this page.SelectAdd key.
Enter a Label for your new key, for example,
Default public key.Paste the copied public key into the SSH Key field.
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 youclone 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
If you don't yet have Sourcetree, go tohttps://www.sourcetreeapp.com/ and click theDownload free button.
Open the ZIP file to install Sourcetree. Refer to theInstall Sourcetree page for more details.
If you don't connect your account during set up, you can add it from theAccounts tab by selectingPreferences from theSourcetree 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:
From theSourcetree menu, selectPreferences.
Click theAccounts tab, select the account where you want to add the SSH key and clickEdit.
Change theProtocol toSSH if it's not already selected.
Hold down the OPTION key on your keyboard to see theGenerate 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 orgenerate another key from the terminal.
Click Generate Key.
Enter a passphrase for the SSH key in thePassphrase andConfirm Passphrase fields.
ClickCreate.
Step 3. Add the public key to your Account settings
From Bitbucket, select theSettingscog on the top navigation bar.
SelectPersonal Bitbucket settingsfrom theSettingsdropdown menu.
The Account settings page opens.Click SSH keys.
If you've already added keys, you'll see them on this page.Select your account from yourAccounts tab in Sourcetree.
Click theCopy to Clipboard button to copy your public SSH key.
From Bitbucket, clickAdd key.
Enter a Label for your new key, for example,
Default public key.Paste the copied public key into the SSH Key field.
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 youclone 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.
Was this helpful?
- Configure SSH and two-step verification
- Set up personal SSH keys on Linux
- Managing multiple Bitbucket user SSH keys on one device
- Enable two-step verification
- Supported SSH key formats
Set up SSH with Sourcetree