Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Permission denied (publickey). fatal: Could not read from remote repository.

Chuck
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 11, 2014

I have an individual bitbucket account and am a member of a team on bitbucket.

Recently I created a new bitbucket repository on my individual account and pushed code from a local repository into it. I then transfered that repository from my individual account to my team account, and I accepted the transfer on behalf of my team.

After making some changes on my local code base i tried to push those changes to origin with a git push and received the following error message:

nw-client (master)]$ git push
fatal: https://[myname]@bitbucket.org/[myname]/nw-html-client.git/info/refs?service=git-receive-pack not found: did you run git update-server-info on the server?

I realized at that point that I needed to update my origin's URL, so I typed the following git command into the terminal:

git remote set-url origin git@bitbucket.org:[myteamname]/nw-html-client.git

But,

git ls-remote

returns

[nw-client (master)]$ git ls-remote
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

My git.config file looks like this:

[core]
	repositoryformatversion = 0
	filemode = true
	bare = false
	logallrefupdates = true
	ignorecase = true
	precomposeunicode = false
[remote "origin"]
	url = git@bitbucket.[myteamname]/nw-html-client.git
	fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
	remote = origin
	merge = refs/heads/master

What am I doing wrong? Any help would be greatly appreciated!

19 answers

1 accepted

24 votes
Answer accepted
rsperafico
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 13, 2014

Hi Chuck,

Thank you for your question.

It seems you had your repository under the HTTPS protocol and once you set the URL origin your repository became to connect under the SSH protocol. Would be possible to generate a key-pair, add the public key to your Bitbucket repository and the private key to your ssh and give it a try, please.

Kind regards,
Rafael

Chuck
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 24, 2014

That was it. Thanks!

Like # people like this
Helton Denis
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 29, 2018

Thanks!

Like avilov.ivan likes this
theaiacademy August 14, 2018

Rafael,

I had the same issue and followed your suggestion. Looks like the initial issue was solved but now I'm not able to perform a push of my commit due to this error:

 

repository access denied. access via a deployment key is read-only.

fatal: Could not read from remote repository.
Like Polina Krol-Kovalova likes this
rsperafico
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 14, 2018

Hi @theaiacademy,

The first thing that comes to my mind relates to the SSH key used having 'Read' permissions and not 'Read/Write' permission.

Please, refer to SSH access keys for system use documentation for further information.

Kind regards,

Rafael

Like # people like this
theaiacademy August 14, 2018

Rafael,

for some reason I don't get the Read, Read/Write options shown on step 5 in the document you shared. 

Screen Shot 2018-08-14 at 10.02.23.png

 

Under myrepository/settings/access keys looks like I'm given only the option to add read-only keys:

Screen Shot 2018-08-14 at 10.04.09.png

I am the owner/admin of the repository I'm trying to commit to.

How can I enable the Read/Write option?

 

thanks

Like Abhishek Sharma likes this
rsperafico
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 14, 2018

Hi @theaiacademy,

The screenshot you have provided suggests your repository is on Bitbucket Cloud (https://bitbucket.org).

The documentation mentioned (SSH access keys for system use) relates to Bitbucket Server instead.

Perhaps, go to your user account in Bitbucket Cloud and add SSH key from there instead (Cog icon >> Bitbucket settings >> Security >> SSH keys)

Kind regards,

Rafael

Like # people like this
theaiacademy August 14, 2018

Rafael, I followed your instructions but can't really say conclusively if it worked: when I tried to run the push command I got an error about the URL not found. I changed the type of repository from SSH to HTTPS in Sourcetree, which changed the URL. When I attempted the push again I was prompted with a window to enter the bitbucket credentials (due to the HTTPS method) and I was finally able to make the commit but I can't say if the the SSH keys configured in the server side had anything to do - probably not.

In any case the Add SSH keys window was also without Read/Write option.

Quick question: the SSH key set in the server section would be global for anything on the bitbucket account (as opposed to specific to the repository)?

thanks again for the help

Carmelo 

Like # people like this
antonagape
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 26, 2018

@theaiacademy @rsperafico

 hey bro, i got some error with carmelo. I cant find the read n write option after follow this instruction: (Cog icon >> Bitbucket settings >> Security >> SSH keys)

Like # people like this
shubham_jaiswal
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 25, 2020

Thanks

Oudy1st
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 23, 2020

@theaiacademy  I found that you should add it from Personal Setting > ssh keys 
which will allow your app to read/write any repo. (I use SourceTree.)

26 votes
Sergio Hernandez
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 28, 2019

I had the same problem, but I solved when I changed remote url to HTTPS with this command:

git remote set-url origin <bitbucket_URL>

After that, I could push the content to the repository with this command:

git push -u origin --all
Emeka Kalu-Ottah
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 4, 2019

This helped me, thank you!

gozpell
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 5, 2019

this worked for me! 👌🏻 thank you 👍🏻 

Terica Douglas
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 29, 2019

I used Sergio's code including the "https://".

This is a great little switching tool! Thank you; the local repo is IN! 

Nitesh Gour September 5, 2019

Thanks

Jesus Melendez
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 6, 2019

thanks

Five stars

Excelent solution

(enviroment Windows 10)

Francis Roberto
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 1, 2020

worked for me. thanks!

andrei9669
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 5, 2020

thank you, this worked like a charm :D

Gabriel Guillamon
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 25, 2020

Like!!

Richard Williams
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 25, 2021

That fixed it for me thanks

Like Alejandro Cortes likes this
5 votes
Jan Nielsen
Contributor
September 23, 2018

If you have multiple SSH identities, you will likely need to setup an SSH config file to allow git+ssh to select the correct identify

Greg Cadmes
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 30, 2019

This worked for me, thank you.

Jack Daniels
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 12, 2020

You saved my life! It's works.

2 votes
Deleted user June 8, 2019

These answers pointed me in the right direction. I had a similar issue pushing after I cloned from my bb repo to a rasp pi and couldn't the push changes to origin master. I had already added my linux pi's ssh public key to the bb keys but still got fatal error. I changed git config to use https by using 

git remote set-url origin https://someusername@bitbucket.org/.../somerepo.git

and then could push as expected.

Ntegeka
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 21, 2019

This helped me too.Thanks

2 votes
Anil Prajapati February 25, 2019

Just change the url of your remote in your local git

`

git remote set-url origin git@bitbucket.org:[myteamname]/nw-html-client.git

`

And then force push all to remote

git push -u origin --all
1 vote
fastfeth
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 13, 2019

In my case, the build machine had been misconfigured - the id_rsa and id_rsa.pub files were owned by root, so the local jenkins account could not read from the private key to authenticate!

The solution was to change ownership of these files to the local jenkins user:

$ sudo chown jenkins ~jenkins/.ssh/id_rsa ~jenkins/.ssh/id_rsa.pub

where "jenkins" is the name of the account our jenkins build manager uses to login and conduct a build.

1 vote
moyyappa
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 22, 2018

ssh -agent -s

ssh-add ~/.ssh/id_rsa 

0 votes
Mikael Sandberg
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 3, 2021

Testing my ability to post under bitbucket questions

0 votes
Bryan Villafañe
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 15, 2020

This is what it worked for me:

eval "$(ssh-agent -s)"   
0 votes
MD ABU TALHA
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 3, 2020

you can delete all cached keys before

$ ssh-add -D

 Then, Again add your keys by,

$ ~/.ssh/id_rsa_your_key

Now you can push,pull. 
Everything will be okay now. :) 

0 votes
afsarpervez
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 1, 2020

Nice! It works.

First I checked If I have existing SSH key from GIt Bash

I saw I have generated it already unconsciously :) as I am a newbie.

Then I run the SSH file in the background 

After that, I have copied the code and added to my git account from settings

Now I can push my files remotely 

0 votes
CTLarsen
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 19, 2020

This was the fix that worked for me without needing to switch to HTTPS url:

 

https://community.atlassian.com/t5/Bitbucket-questions/could-not-read-from-remote-repository/qaq-p/983015#M45418

0 votes
Drew Jaqua
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 30, 2019

I followed the bit about 

git push -u origin --all

and noticed that -- even though it didn't work -- I was able to get a little bit more information about the problem. I pared down the possible causes until I knew that it had something to do with my feature branch's dependence on another branch. I was able to solve the problem with these two commands

git push -u origin independent_branch 
git push -u origin dependent_branch

 

I hope that helps someone else. 

0 votes
LannaVrevskaya
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 25, 2019

Hello!

I am also unable to manage a remote repository.

The errors are:

 

fatal: protocol 'git clone https' is not supported

 

git -c filter.lfs.smudge= -c filter.lfs.required=false --no-optional-locks -c color.branch=false -c color.diff=false -c color.status=false -c diff.mnemonicprefix=false -c core.quotepath=false -c credential.helper=sourcetree clone it@bitbucket.org:LannaVrevskya/remotesourcetree.git /Users/lannavrevskya/remotesourcetree

 

Please make sure you have the correct access rights

and the repository exists.

Cloning into '/Users/lannavrevskya/remotesourcetree'...

it@bitbucket.org: Permission denied (publickey).

fatal: Could not read from remote repository.

 

Will be glad to get a solution.

0 votes
aheikki
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 25, 2019

Also remember to check if you have double SSH keys loaded in your agent. I had 2 valid SSH keys for bitbucket.org, but the another one was for completely different Bitbucket account.

I have MacOS and I use ~/.ssh/config file. Also debugging with "git -Tv -i path_to_my_key_file git@bitbucket.org" seemed to work fine, it even said it loaded the right key file succesfully. Only difference was the username.

ssh-add -D # Use this to remove all keys from agent

ssh-add ~/.ssh/my_specific_id_rsa # Only load the one you need

I have used to normally type in just:

ssh-add # WITHOUT specifying a key, it loaded the default "id_rsa" key and I then had 2 bitbucket keys loaded into agent

So heads up for everyone with multiple Bitbucket accounts. 

0 votes
Seamus Roche
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 12, 2019

In my case, I was erroneously passing my user ID in my set-url command.  I updated and set remote by omitting the user ID from this command. This solved the issue for me:

git remote set-url origin git@bitbucket.org:myGitRepo.git

 

0 votes
Renetik
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 25, 2018

The problem is that sourcetree is loading url of remote when you add it by that button with link git@github.com:rene-dohan/ but then it is failing with that git error

Permission denied (publickey). fatal: Could not read from remote repository.

and you have to change it manually to https://rene-dohan@github.com/rene-dohan/ , its clear bug on side of sourcetree but I think they just didn't get it yet... 

PS:

1 - sure you have to modify links I posted to yours ;) haha

2- Anyway nice program for the price :)

0 votes
sjoerdo July 3, 2018

I also encountered a similar problem recently, I could load my remote repositories but not clone/pull/push etc. As has happened before this had to do with locally adding the ssh key to my ssh-agent. This is a problem I've run into more often on mac. I found this article very useful:

https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/#adding-your-ssh-key-to-the-ssh-agent

0 votes
Peter Coxhead February 15, 2016

I encountered the same problem but it my public ssh key was registered.  It turned out to be simply a DNS issue.  Once the hostname resolved everything was happy.

Giddy
Contributor
October 17, 2017

Could you provide more detail to this?

Peter Coxhead October 17, 2017

I'm sorry I don't recall much more than that.  I may have changed which network interface I was using to connect to the network or perhaps the IT department moved the repo to a new machine / IP address (thought that's unlikely).

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events