Can't git push to Bitbucket: Unauthorized - fatal: Could not read from remote repository
GitBitbucketGit Problem Overview
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.
Git Solutions
Solution 1 - Git
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: