90

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.

1
  • 3
    Great questions helps 1000s of life. Your question and the answer saved my day. thanks!
    – Ramesh KR
    Aug 12, 2020 at 19:12

1 Answer 1

250

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

11
  • 25
    They could explain that better. Most times someone wants to add a key to push and not to read only.
    – kev
    Feb 8, 2020 at 2:13
  • 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, 2021 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
    – asugrue15
    Feb 24, 2022 at 16:30
  • 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 7, 2022 at 0:00
  • 1
    The link to your account ssh settings bitbucket.org/account/settings/ssh-keys
    – latsson
    Sep 19, 2022 at 7:43

Not the answer you're looking for? Browse other questions tagged or ask your own question.