Can't push to my own repo (have SSH keys in personal settings)
Asked by Erik Trauschke:

Hi,

I created a new (not private) repository and cloned it to my system. When I want to push changes to the remote, I get this:

```
The requested repository either does not exist or you do not have access. If you believe this repository exists and you have access, make sure you're authenticated.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
```

I saw a lot of posts about this on-line and they all seem to be about people using access tokens instead of having SSH keys. However, I have working SSH keys:

```
$ ssh -T git@bitbucket.org
authenticated via ssh key.

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

I also can push to other repositories for which I have write access however, with all the repos I create for myself I seem to have this issue. If I make the repo private, I can't even clone it.

Any ideas what I'm doing wrong?


Answers:
author: Patrik S
body: Hello [@Erik Trauschke](/t5/user/viewprofilepage/user-id/3496134) ,

Thank you for reaching out to Atlassian Community!

The error you are receiving is most likely because the ssh key being used does not have the required permissions in the repository you are trying to push to.

The test with the ssh command you have used confirms the SSH key used is recognized by bitbucket for **authentication** , but when pushing to a repository, bitbucket also checks for **authorization** to confirm if that key has access to the content you are trying to read/write.

When you add an ssh key to your **personal settings**, this key will have the same access as your account, so your account needs to have write permissions to the repository you are pushing to.

Another thing that might be happening if you have multiple SSH keys in your local machine, is that the wrong key is being presented to git. In order to check what the key ssh is trying to use you can run the following command to include verbose logs :

```
GIT_TRACE_PACKET=1 GIT_TRACE=1 GIT_SSH_COMMAND="ssh -vvv" git push
```

That will include ssh logs of the keys that were found and the order of precedence that ssh will attempt to use them.

By default in SSH, the first key that passes authentication will be used, but that does not necessarily mean that key has access to the repository in question. So make sure to identify if the key being used is the one you have added to the bitbucket account that has access to the repository.

In case you indeed use multiple SSH keys, you might need to do some extra configurations for the correct SSH to be used for each user. You can refer to the following blog post with detailed instructions on how your local environment needs to be configured :

* <https://blog.developer.atlassian.com/different-ssh-keys-multiple-bitbucket-accounts/>

Hope that helps! Let me know in case you have any questions.

Thank you, [@Erik Trauschke](/t5/user/viewprofilepage/user-id/3496134) !

Kind regards,

Patrik S

comments: author: Erik Trauschke
body: Hi Patrik,

Thanks for responding. These are some useful env variables to know about so I used them and it looks like everything is working as expected. I only have one key for this computer that is registered with bitbucket.

Regarding the access rights, I can log into bitbucket and edit files right there without any issues. I also tried to edit access rights directly, like adding myself as an admin, but it doesn't let me do that because I'm already the owner of the repo so should have explicit admin rights.

Erik


author: Patrik S
body: Hey [@Erik Trauschke](/t5/user/viewprofilepage/user-id/3496134) ,

Could you confirm that the ssh key you identified is being used in the verbose logs, and was added to your bitbucket account under Personal settings as described in [Provide Bitbucket Cloud with your public SSH key](https://support.atlassian.com/bitbucket-cloud/docs/set-up-personal-ssh-keys-on-linux/#Provide-Bitbucket-Cloud-with-your-public-key)

I ask this because if your key was added directly to a [**Project**](https://support.atlassian.com/bitbucket-cloud/docs/set-up-project-access-keys-on-linux/#Provide-Bitbucket-Cloud-with-your-public-key) or **[Repository](https://support.atlassian.com/bitbucket-cloud/docs/set-up-repository-access-keys-on-linux/#Provide-Bitbucket-Cloud-with-your-public-key)** as an **Access key,** they will provide you with just **read** access to the repository, regardless of your account permissions. This would explain why you are not being able to push.

For the ssh key to have the same access as your account, you need to add them in your account's personal settings.

Thank you, [@Erik Trauschke](/t5/user/viewprofilepage/user-id/3496134) !


author: Erik Trauschke
body: Hi Patrik,

I checked again and it is in fact picking up a key that I didn't realize I had in my setup. I will go and see how to change git to use a particular key and not the one found first.

Thanks for your help.

Erik


Tags: bitbucket-cloud

cloud