The requested repository either does not exist or you do not have access error in SSH git operations
Platform Notice: Cloud - This article applies to Atlassian products on the cloud platform.
Problem
When attempting to clone, push or pull over SSH with Git, you receive the message
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
and the repository exists.
Diagnosis
You are receiving this message because Bitbucket Cloud could not authenticate you with any of the keys that were offered to it by your SSH agent. To verify this is the case, do the following
ssh -t -vvv git@bitbucket.org
This will attempt to create a connection to Bitbucket Cloud for git. You should receive a response similar to the following if your key is correctly loaded
$ ssh -t -vvv git@bitbucket.org
authenticated via ssh key.
You can use git to connect to Bitbucket. Shell access is disabled
From here you can proceed with your work as normal. If you do not see a message similar to the above, read on.
If you see the message "debug3: no such identity: <path_to_your_key>: No such file or directory" refer to Error "No such file or directory" when running verbose git SSH commands.
Resolution
This can be caused by a couple of factors, but these are the most common:
- Your public key isn't added to Bitbucket Cloud
To check to see if your public key is loaded into Bitbucket Cloud, do the following:
- Open a browser and log into Bitbucket Cloud.
- Select the Settings cog and select Personal Bitbucket settings from the profile menu
The system displays the personal settings page. - Click SSH keys in the Security section.
The SSH Keys page displays. It shows a list of any existing keys. Alternatively, you can directly access this URL - https://bitbucket.org/account/settings/ssh-keys/ to list/add/delete SSH keys under your profile. - If you do not have any keys listed, follow Set up an SSH key to set one up.
- Your identity isn’t loaded into PuTTYgen
If using PuTTYgen application:
Open PuTTYgen;
Click on ‘File > Load private key’;
Choose your *.ppk file from a directory;
Click on ‘Conversions > Export OpenSSH key’;
Save the file in ‘C:\Users\<your username>\.ssh folder with 'id_rsa’ name.
- Git bash for Windows/Pageant is not using the correct keys
This can be confirmed by running the following command:
ssh -Tvvv git@bitbucket.org
If you see that your SSH agent isn’t using the key you want to, it’s likely because of Windows Environment Variables. To configure those, follow the steps outlined below:
1. Access your Environment Variables by opening up System Properties and navigating to Advanced System Settings
2. Add a new System variable with the following structure
Variable Name: GIT_SSH
Variable Value: full path to pageant.exe (you may also have plink.exe, puttygen.exe and other agents, i.e. C:\Program Files (x86)\Atlassian\SourceTree\tools\putty\plink.exe)
An easy way of finding the path for the agent is to open Task Manager, find the process, and open the folder location to get the path to your agent.
After creating the new variable make sure to restart your terminals so that they receive the new values. If you’re running bash from an IDE, make sure to restart the IDE itself as well.
- Git is not using the correct keys(Linux/Windows)
If you are using a windows machine, please execute the below commands from Git bash.
1. Run the desired git command using verbose,
GIT_SSH_COMMAND="ssh -vvv" git <command>
2. In the output from the above verbose command, you should see logs similar to,
debug1: Will attempt key: /Users/user/.ssh/id_rsa RSA SHA256:FQlAb45CD7saeAbcDeFgHt6E8bWaQnz4bYONRS0
debug1: Will attempt key: /Users/user/.ssh/id_ecdsa
debug1: Will attempt key: /Users/user/.ssh/id_ecdsa_sk
debug1: Will attempt key: /Users/user/.ssh/id_ed25519
debug1: Will attempt key: /Users/user/.ssh/id_ed25519_sk
debug1: Will attempt key: /Users/user/.ssh/id_xmss
debug1: Will attempt key: /Users/user/.ssh/id_dsa ....
....
Authenticated to bitbucket.org ([104.192.141.1]:22) using "publickey".
3. If you notice, git is trying to use the key id_rsa. There are two possibilities for this error,
a. This key(id_rsa) might have been added to a user's(who doesn't have access to the repository) personal settings, to a different repository(Access keys - grants read-only access), or to a different project's access keys(grants read-only access).
In this case, confirm if you have the necessary access to the repo(read/write) and reach out to an admin for access.
If you need help identifying where this particular SSH key was added, please contact support.
b. The SSH key that's added to Bitbucket Cloud might have been in a different path(and not in /Users/user/.ssh). The SSH client reads the config and tries to use SSH keys stored in a specific path, for instance,
debug1: identity file /Users/user/.ssh/id_rsa type 0
debug1: identity file /Users/user/.ssh/id_rsa-cert type -1
debug1: identity file /Users/user/.ssh/id_ecdsa type -1
debug1: identity file /Users/user/.ssh/id_ecdsa-cert type -1
debug1: identity file /Users/user/.ssh/id_ecdsa_sk type -1
debug1: identity file /Users/user/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /Users/user/.ssh/id_ed25519 type -1
debug1: identity file /Users/user/.ssh/id_ed25519-cert type -1
debug1: identity file /Users/user/.ssh/id_ed25519_sk type -1
debug1: identity file /Users/user/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /Users/user/.ssh/id_xmss type -1
debug1: identity file /Users/user/.ssh/id_xmss-cert type -1
debug1: identity file /Users/user/.ssh/id_dsa type -1
debug1: identity file /Users/user/.ssh/id_dsa-cert type -1
Find out where the SSH key that's added to Bitbucket is stored on your machine. Then add the SSH key to the agent. If your SSH agent doesn't know how to offer Bitbucket Cloud a key, the connection will fail. To find out what keys your SSH Agent currently is offering, and add them, do the following:
Windows
1. Double-click Pageant to view loaded keys (Pageant is a PuTTY authentication agent).
2. Click 'Add Key' to add any key not found in the list.
If you see an invalid format error, make sure you remove all of the new line characters and spaces from the key. In the example above, the last character should be 6.
On GitBash, MacOS or Linux
1. List SSH keys added to the agent,
$ ssh-add -l
2. Then, if you don't see your key listed, add it by
ssh-add <path to your SSH private key>
Example: ssh-add ~/.ssh/id_rsa
On PuTTYgen:
If using PuTTYgen application:
1. Open PuTTYgen;
2. Click on ‘File > Load private key’;
3. Choose your *.ppk file from a directory;
4. Click on ‘Conversions > Export OpenSSH key’;
5. Save the file in ‘C:\Users\<your username>\.ssh folder with 'id_rsa’ name.
If none of the solutions above worked you can always contact our support team via the support portal at https://support.atlassian.com/. Feel free to open a ticket with us containing as much information as possible, especially which repository are you trying to access as well as your public SSH key, which can be found by using the following command:
cat id_rsa.pub | pbcopy
This will copy the contents of your public SSH key and will be ready to be pasted on the support ticket.