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.
I was able to solve this using this suggestion:
- Remove the SSH key from the repo. (Click on repo name > Settings > Access Keys)
- Add SSH key to Account settings SSH keys. (Next to your avatar click Settings > Personal Bitbucket 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: