SSH Key error while pushing info to BitBucket

When I used Ruby on Rails to create sample project on my virtual machine using Ubuntu, I created an SSH key and saved in the folder ~/.ssh/

I have also saved this SSH key on Bit Bucket.

But error of invalid key comes when try to push this.

When I use cloud environment for ROR projects, I could push the information of the project to Bit Bucket without any error.

Also in Ubuntu 2 separate SSH keys were created probably when I was in 2 different directories like ~/workspace or ~/workspace/hello_app

I however uploaded both the SSH keys on Bitbucket.


So how to resolve the error when trying to push the info to Bitbucket repository from my virtual machine using Ubuntu.



4 answers

0 votes
Boris Berenberg Community Champion Jun 10, 2015

What is the actual error you are getting?

I am getting the following error:

~/workspace/hello_app$ git push -u origin --all

Permission denied (publickey).

fatal: Could not read from remote repository.


Please make sure you have the correct access rights

and the repository exists.

I created the key as follows and copied the public key to the directory  ~/.ssh/ :

$ ssh-keygen -t rsa (this command was made while in home directory)

Generating public/private rsa key pair.

Enter file in which to save the key (/home/venkata/.ssh/id_rsa): id_rsa

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in id_rsa.

Your public key has been saved in

and then using cat command, displayed and then copied to Bitbucket. The repository hello_app was created in BitBucket. Presently this repository is empty.











0 votes

Hi Venkata, 

Can you let us know what happens when you run the following command?

$ ssh -T

This might not be your case, but as a quick test, what happens if you run the push command using sudo in front of?


Also, this can happen due to a variety of reasons such as 1) your public key not loaded in your Bitbucket account 2) your key not loaded onto your ssh-agent etc.

This document does a good job of walking you through the process of troubleshooting your problems. There is a specific section for the Permission denied (publickkey) error as well that you might find useful.



Renato Rudnicki

I found out the error. When I generated key while in ~/.ssh/ instead of generating it while in another directory,  the key started working and I could push the info to repository. Thank you.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Mar 14, 2019 in Bitbucket Pipelines

Building a Bitbucket Pipe as a casual coder :  #!/bin/bash source "$(dirname "$0")/" enable_debug extra_args="" if [[ "${DEBUG}" == "true" ]]; then extra_args="--verbose" fi # mandatory variables R...

267 views 0 12
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you