How to create an SSH key that works with Bitbucket and Sourcetree
A step by step guide on creating and using an SSH key that works with Bitbucket and Sourcetree which solves the Permission denied (publickey) error.
The following tutorial solves the issue that arises by which you can perform operations on a Bitbucket git repository using Terminal but not with Sourcetree.
This issue produces the following error message:
The error arises if you do not create an rsa ssh key. Here's how to create one.
Step One: Install OpenSSH
Run the following line in Terminal to check if you have OpenSSH installed
ssh -V
If you don't install it using Homebrew, by running the line below:
brew install openssh
Step Two: Create SSH Key
Run the following line in Terminal to create an rsa ssh key:
ssh-keygen -t rsa -b 2048
Step Three: Add to id_rsa
Run the command below to add the key to your systems ssh agent:
ssh-add ~/.ssh/id_rsa
Step Four: Copy to the key to your clipboard
Run the following command in Terminal to copy the key.
cat id_rsa.pub | pbcopy
Use this key to create a new SSH key in Bitbucket.
Remaining Steps
In order to successfully use this key with Bitbucket and Sourcetree you must:
- Add the ssh key to your Bitbucket account.
- Connect your Bitbucket account with Sourcetree.
To learn how to do this, consult the guides below.