When using our Bitbucket origin from a new computer, we will usually find this message:
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
That’s normal. Bitbucket does not trust our computer yet, we have to add its key to the list of trusted hosts.
If you already have a SSH key, copy it and add it to bitbucket.
First, to copy it, open a terminal and write the following
cd ~/.ssh/
cat id_rsa.pub
Then you will find something like this*
ssh-rsa AAAB3NzaC1yc2EAAAADAQABAAABAQDGf57XkGtFONIn5fskaF1/6obxgLUq3r+lnyUkBJP6qIOyJ+0K[…]OdecdoOL8hQZagq+ff3X23GwfvJPj1Ytf your.mail@company.com
Copy this key in your clipboard, then log in into Bitbucket and do the following:
1.- Click on the user account icon (in the top-right of the screen)
2.- Then on “Bitbucket Settings”
3.- Now, under “Security”, click on “SSH Keys”
4.- Click on “Add key”
5.- Now assign a name to your key (e.g.: “My Laptop key”) and paste your clipboard inside the “Key” field. Click on “Add key”.
* If there is no id_rsa.pub or any .pub files, go to “Generating a new SSH key” section
Generating a new SSH key
In order to generate a new SSH key, write the following
ssh-keygen -t rsa -C “your_mail@company.com”
Generating public/private rsa key pair.
Enter file in which to save the key (/home/olmo/.ssh/id_rsa): mykey
Enter passphrase (empty for no passphrase): passphrase
Enter same passphrase again: passphrase
Your identification has been saved in mykey.
Your public key has been saved in mykey.pub.