97

I can't push to Bitbucket and this is the error message:

> git push origin master:master
Unauthorized
fatal: Could not read from remote repository.

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

Debugging, I receive this message when I ssh to bitbucket:

> ssh -T bitbucket.org
authenticated via a deploy key.

You can use git or hg to connect to Bitbucket. Shell access is disabled.

This deploy key has read access to the following repositories:
my-username/my-repository

The read access part of this message is suspicious.

PS: I know there are dozens of similar questions, but I couldn't find the exact error message here and only got the solution outside. That's why I'm self answering this to help others.

Zanon
  • 29,231
  • 20
  • 113
  • 126

1 Answers1

267

I was able to solve this using this suggestion:

  1. Remove the SSH key from the repo. (Click on repo name > Settings > Access Keys)
  2. Add SSH key to Account settings SSH keys. (Click on your avatar > Personal Settings > SSH Keys)

So, adding the keys under the repo only gives you a read-only access. For read and write access, you need to add your keys under your account.

To be fair, Bitbucket warns about the read-only access when adding the key to the repo: image showing the bitbucket message warning about the read-only access

CodeHealer
  • 401
  • 1
  • 4
  • 16
Zanon
  • 29,231
  • 20
  • 113
  • 126
  • 29
    They could explain that better. Most times someone wants to add a key to push and not to read only. – kev Feb 08 '20 at 02:13
  • Works, but won't this give my collaborators access to all my repos? – Kermit Mar 14 '20 at 19:11
  • @HashRocketSyntax, the key for the account will have full access for the account's repos, but you shouldn't share your account key with your collaborators. Each one of them must have their own account/key and you give repo permissions for each account. – Zanon Apr 06 '20 at 17:19
  • But what about a service account that won't have a Bitbucket account? A remote server perhaps. I've just inherited an unversioned codebase and this issue of not being able to push to a new repo is driving me mad. – badcrocodile Apr 18 '20 at 05:35
  • I had this issue on bitbucket and wondering if it is also true in github. – darth vader Sep 29 '20 at 15:57
  • 5
    It took me a while to find these settings. For those who can't find them, goto bitbucket.org, click on your avatar on the bottom left of the screen, select "Personal Settings" then "SSH keys" – Eddy Mar 16 '21 at 19:27
  • 1
    Further to @Eddy, you need to get to your Bitbucket profile rather than your Atlassian profile. Here is the current [link](https://bitbucket.org/account/) – asugrue15 Feb 24 '22 at 16:30
  • didn't work for me.....unfortunately something strange is happening with keys and bitbucket, as well as github – Vladimir Despotovic Jun 26 '22 at 22:31
  • 1
    tiny but important addition. if you added your public key to some repo in Bitbucket , it will NOT let you add the same key at the project level. As others said, this key can only be used for read only (git pulls) and Bitbucket checks uniquness. you can either key gen 2nd pair of keys or remove the key and add it to the site access for r/w – Vortex Jul 07 '22 at 00:00
  • 2
    The link to your account ssh settings https://bitbucket.org/account/settings/ssh-keys/ – latsson Sep 19 '22 at 07:43
  • create here: https://bitbucket.org/account/settings/ssh-keys/ – Softsofter Oct 18 '22 at 05:00