Add SSH Key To BitBucket
How to add an SSH key to BitBucket
The following is a quick guide on how to add an SSH key to BitBucket on a linux machine.
If you ever see this error when trying to push to BitBucket, you need to add your SSH key to BitBucket.
git push
git@bitbucket.org: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
SSH Key Generation
If you have not already used SSH on you machine you will need to create an SSH public/private key pair. You can do this by running the following command.
ssh-keygen -t rsa -b 4096
WARNING
rsa is widely supported, but it is older, and you may be advised to use a newer algorithm.
This will create a public/private key pair in the ~/.ssh directory. The public key will be named id_rsa.pub and the private key will be named id_rsa.
Add SSH Key To BitBucket
To add the SSH key to BitBucket, you need to go to the BitBucket website and login. Once logged in go to URL https://bitbucket.org/account/settings/ssh-keys/.
Click on the Add Key button and paste the contents of the public key file into the Key field. You can give the key a name in the Label field. Once you have entered the key and label, click on the Add Key button.
Conclusion
There are a lot of outdated guides for how to do this out there. I assume sooner or later this too will become outdated. I hope this helps someone until then.