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

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!

5 answers

1 accepted

7 votes
Accepted answer

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

That was it. Thanks!

Thanks!

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.

Hi @carmelo,

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

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

Hi @carmelo,

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

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 

@carmelo @Rafael Sperafico

 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)

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.

Could you provide more detail to this?

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).

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

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

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 :)

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 06, 2018 in Bitbucket

Upgrade Best Practices

Hello! My name is Mark Askew and I am a Premier Support Engineer for products Bitbucket Server/Data Center, Fisheye & Crucible. Today, I want to bring the discussion that Jennifer, Matt, and ...

211 views 3 7
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