Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Clone via ssh does not work in new workspace while https works

guynimni
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 13, 2023

I have my personal workspace with some repos.
I manage to clone repos from my personal workspace via ssh.

I created a new workspace and I try to clone a repo from that new workspace via ssh but I fail with "fatal: Could not read from remote repository.".
The weird thing is that I manage to clone that same repo using https.

Do you have an idea what might be wrong?

Note that I created a new ssh key just to make sure it's not that but I still get the same problem.

Also tried running "ssh -T git@bitbucket.org" and got: "

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

1 answer

1 accepted

0 votes
Answer accepted
Patrik S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 14, 2023

Hello @guynimni and thank you for reaching out to Atlassian Community!

 

The results from the ssh -T bitbucket.org  command indicates the SSH key used is indeed being recognized by Bitbucket (the authentication succeeded), but that does not necessarily mean that the key has the authorization to perform the operation in the workspace/repository you are receiving the error.

In this case, could you please confirm if you have added the key to your bitbucket profile (Personal Settings > SSH Keys), or directly in the workspace/project/repository as an Access key? SSH Keys added to the bitbucket profile will provide you with the same level of access to repositories as your account has.

Also, as you mentioned you have multiple keys in your local environment, to make sure the correct key is being used to authenticate with Bitbucket, you can create a file named config under the folder  ~/.ssh/ with the following content : 

Host bitbucket.org
     HostName bitbucket.org
     User git
     IdentityFile ~/.ssh/<name of your ssh private key>
     IdentitiesOnly yes

This will instruct SSH to use the key in the path provided on IdentityFile option. If your key is in a different path please update the value of IdentityFile accordingly. Also, make sure the private key provided in the config file is the key to which the corresponding public key was added to your Bitbucket profile.

You can then confirm the correct key is being used by cloning the repository with verbose logs enabled : 

GIT_TRACE_PACKET=1 GIT_TRACE=1 GIT_SSH_COMMAND="ssh -vvv" git clone git@bitbucket.org:<workspace>/<repository>.git

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

Thank you, @guynimni !

Patrik S

guynimni
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 16, 2023

Hey Patrik,
Thanks a lot for the response.

I followed your suggestion but still didn't manage to succeed with cloning via ssh.

This is my full config:

Host bitbucket.org

  HostName bitbucket.org

  User git

  IdentityFile ~/.ssh/id_ed25519

  IdentitiesOnly yes

 

Host *

 AddKeysToAgent yes

 UseKeychain yes

 IdentityFile ~/.ssh/id_rsa

and I also checked and this is the key that was added to my personal settings in Bitbucket.

 

I also ran the git command you pasted and got:

fatal: Could not read from remote repository.

 

Please make sure you have the correct access rights

and the repository exists.

debug3: send packet: type 1

debug1: fd 0 clearing O_NONBLOCK

debug3: fd 1 is not O_NONBLOCK

Transferred: sent 2836, received 3168 bytes, in 0.3 seconds

Bytes per second: sent 8511.7, received 9508.1

debug1: Exit status 1

 

BUTTTT :)

I saw at the top of the clone verbose command that it's using both keys.
Long story short, I had to exclude bitbucket from the second section of the config file:

Host bitbucket.org

  HostName bitbucket.org

  User git

  IdentityFile ~/.ssh/id_ed25519

  IdentitiesOnly yes

 

Host * !bitbucket.org

 AddKeysToAgent yes

 UseKeychain yes

 IdentityFile ~/.ssh/id_rsa

 

So again, I appreciate your help!
Just saved my day :)

Like Patrik S likes this
Patrik S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 16, 2023

Hello @guynimni ,

Awesome! Thank you for sharing the config that solved the issue and happy to have been of some help :) 

If you ever need assistance, feel free to reach out to Community!

Kind regards,

Patrik S

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events