fatal: Could not read from remote repository.
Asked by Francesco Savino:

I have followed all steps to create remote repo ,Created SSH keys pair, and also been succed to clone repo locally .To day after , now , created some folders and done staging +commit .

Now I cant be able to push :

$ git push origin master  
Enter passphrase for key '/home/devuser/.ssh/bitbucket':  
Unauthorized  
fatal: Could not read from remote repository.

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

I inserted also in .ssh/config file :

`Host bitbucket.org `

`AddKeysToAgent yes `

`IdentityFile ~/.ssh/{ssh-key-name}`

It's is strange because all git read operations works and `test work fine `

$ ssh -T git@bitbucket.org  
Enter passphrase for key '/home/devuser/.ssh/bitbucket':  
authenticated via ssh key.

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

Then where is the problem ? please , help :)


Answers:
author: Patrik S
body: Hello [@Francesco Savino](/t5/user/viewprofilepage/user-id/5145857) ,

Welcome to Atlassian Community!

As you mentioned that read operations (clone, pull) work and the issue happens only with write operations (push), I suspect you might have added the SSH key as an Access key.

SSH keys added as Repository or project access keys provide just **read** access to repositories. So you will be able to only clone and pull using a repo/project access key. The only access key that provides read and write access are Workspace Access keys (see [Difference between repository, project and Workspace access keys](https://confluence.atlassian.com/bbkb/difference-between-repository-project-and-workspace-access-keys-1188785759.html) ).

If you want the key to have the same access to repositories as your user account does, then you need to add the key to your user profile by going to **Your avatar in the top right \> Personal Settings \> SSH keys**.

It's important to note that you cannot use the same key both as access keys and personal keys.

With that in mind, could you please confirm if the key you are using was added as an access key at the repo or project level? If yes, you can then try either adding it as a personal key or as a workspace access key.

Thank you, [@Francesco Savino](/t5/user/viewprofilepage/user-id/5145857) !

Patrik S

comments: author: gh_inet
body: Hi [@Patrik S](/t5/user/viewprofilepage/user-id/4603309) ,

It seems that I have a similar problem. I changed the computer and added a second SSH key, which I created new on my second laptop.

```
 ssh-keygen -t rsa -b 2048 "gerXX.XXX@gmail.com" -f id_bitbucket
```

<br />

Then I added the SSH key to my account (Personal Settings \> SSH keys).  

The test is working:

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

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

I still get

```
> git pull --tags origin master
Unauthorized
fatal: Could not read from remote repository.

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

Thank you for your help!

<br />

Kind regards,

<br />

Gernot


author: Patrik S
body: Hello [@gh_inet](/t5/user/viewprofilepage/user-id/5286876) ,

I suspect the new key you created is not being used by SSH. To confirm if that is the case, could you please create a file named **config** inside the folder **\~/.ssh/**and add the following content to it :

```
`Host bitbucket.org`
`AddKeysToAgent yes`
`IdentityFile ~/.ssh/{name of your SSH key}`
```

The IdentityFile section should contain the full path to the new key you created. This will force SSH to use the provided key when authenticating requests to bitbucket.org.

You can also try using the verbose flags in the git command so it will output logs containing more details about the ssh keys that were found in your local machine and the order they are being used :

```
GIT_TRACE_PACKET=1 GIT_TRACE=1 GIT_SSH_COMMAND="ssh -vvv" git pull --tags origin master
```

Thank you, [@gh_inet](/t5/user/viewprofilepage/user-id/5286876) !

Patrik S


author: kuno vaik
body: I have same error.

i added config file, but this is not resolved the problem.


author: Patrik S
body: Hello [@kuno vaik](/t5/user/viewprofilepage/user-id/782369) ,

I would like to ask if you could please create a new question for your issue, providing details on the errors you see and also the output of the git command with the verbose log flags as mentioned above.

We generally encourage users to create a new question for their issue instead of posting on someone else's question, because

1) the root cause and resolution may be different for each case

2) a question can become cluttered and difficult to follow if we try to troubleshoot multiple users' issues in it.

Please feel free to let me know if you have any questions.

Thank you, [@kuno vaik](/t5/user/viewprofilepage/user-id/782369) !  
Patrik S


Tags: atl-orange

bitbucket-cloud

cloud