Search code examples
gitsshbitbucketopenssh

Trouble cloning a git repo using ssh with a secondary (non default) public key


I am trying to access an old git repo on BitBucket via SSH. The SSH key has not changed on either the client or BitBucket, but cloning the repo is failing.

git clone [email protected]:william_ferguson_au/lexathon-server.git
Cloning into 'lexathon-server'...
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.

Variations on the command as suggested by responders:

git clone ssh://[email protected]/william_ferguson_au/lexathon-server.git
Cloning into 'lexathon-server'...
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.


git clone ssh://[email protected]:william_ferguson_au/lexathon-server.git
Cloning into 'lexathon-server'...
ssh: Could not resolve hostname bitbucket.org:william_ferguson_au: Name or service not known
fatal: Could not read from remote repository.

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


I have tried creating a new SSH key and uploading it to BitBucket as suggested by https://confluence.atlassian.com/bitbucketserverkb/git-clone-fails-when-cloning-via-ssh-879243661.html, but it had no effect.

Can someone point me in the right direction please.

NB the repository exist and I have the correct access rights. How do I know this ? Because I have this repository cloned elsewhere on this same machine and I am able to push to it.


Solution

  • OK, so using

    set GIT_SSH_COMMAND=ssh -vvv
    git clone git@<bitbucket URL>:<project key>/<repository slug>.git
    

    I can see that it is authenticating with BitBucket using the default ssh public key (.ssh/id_rsa), but it then fails to find that repo because the user for the default public key doesn't have access to that repo.

    What I needed to do was to append "-" plus the project key to the BitBucket URL. ie

    git clone git@<bitbucket URL>-<project key>:<project key>/<repository slug>.git
    

    This finds the correct public key to authenticate with for the BB repository. Authenticate succeeds and the repo is found and cloned.