1

We have a weird issue with our git repository. We reference two submodules (not sure if it matters: the one that makes troubles lies on bitbucket cloud while the repo and the other submodule lie on the same bitbucket server instance)

If someone wants to freshly check out the repository, they get the following error:

Cloning into local/path…
Warning: Permanently added the RSA host key for IP address 
xx.xxx.xxx.xxx to the list of known hosts.

Permission denied (publickey).
fatal: Could not read from remote repository.

What I would expect is not properly setup ssh keys but here comes the odd part: If we manually copy over the submodules contents through the filesystem, from that moment on everything works fine and pulling, switching branches in the submodule etc works just fine.

This made me assume that some of the git settings are in the submodule folders that i am copying over, but actually there are only two git files: The gitignore (which doesnt ignore anything special/suspicious) and a .git file which only contains gitdir: ../../../.git/modules/path/to/submodule

This should not have anything to do with permissions, so can anyone explain why a manual copy fixes the permission issues?

friday
  • 1,358
  • 1
  • 14
  • 23

4 Answers4

1

Adding a key to your local Bitbucket Server instance will update that Bitbucket Server instance. It will not, however, do anything at all to Bitbucket Cloud.

It sounds like you have two options here:

  1. Have users create Bitbucket Cloud accounts, then associate their SSH keys with those accounts.
  2. Use HTTPS for the submodule remote.
Jim Redmond
  • 4,139
  • 1
  • 14
  • 18
  • I am not sure if this answers my question. I am not changing anything about the ssh keys, nor do I switch to https. I simply copy over the contents of the submodule and with that the permission issues vanish. However I have to do that on every new machine, and I am trying to understand how this happens.. – friday Dec 19 '18 at 09:26
  • Could you please read my comment again? It explains the nature of the problem - keys added to Bitbucket Server aren't automatically added to Bitbucket Cloud, so SSH connections to BB Cloud won't work automatically - and offers two independent solutions - add keys, or switch to HTTPS - which will allow you to use Git to clone the submodule. – Jim Redmond Dec 20 '18 at 18:32
  • Hey, very late reply - sorry for that! You are right of course about having to create additional accounts with their own ssh keys, but there is still one thing that does not make any sense to me: Only after manually copying the contents of the submodule, I could go into sourcetree, open the submodule and pull/checkout/.. without any permission problems. Why would the initial checkout require the ssh key but then after manually copying over the contents, the user would magically become authorized to fetch/checkout/pull/push without any ssh errors? – friday Apr 29 '19 at 12:11
1

I ended up removing the submodule since there seemed to be other things weird about it as well. The clone link displayed by bitbucket for example showed "git clone git@bitbucket.org:company/repo-name.git which does not get recognized by sourcetree correctly.. the colon seems to be misplaced, our other repos specify the port and then the route to the repo with slashes only. So whatever was wrong with the repo, it seemed to be wrong in several places and therefore we threw it out completely

friday
  • 1,358
  • 1
  • 14
  • 23
  • 1
    Port 22 is implicit for SSH; if you need to specify a port then the `ssh://` format is necessary, but if you're using port 22 (as with bitbucket.org) then the `git@bitbucket.org:owner/repo` format is valid. – Jim Redmond Dec 20 '18 at 23:25
1

Make sure your submodule uses user git (git@bitbucket.org), and not the current user. I fixed this by adding a config for bitbucket.org in my ~/.ssh/config:

host bitbucket.org
    user git
Pelle
  • 1,222
  • 13
  • 18
0

I had the same error when I try to clone a submodule on mac

git submodule update --init
Cloning into '**** local repo *****'...
git@bitbucket.org: Permission denied (publickey).
fatal: Could not read from remote repository.

it resolved when I have set up the ssh key to local machine and to bitbucket acccount.

Reference: https://confluence.atlassian.com/bitbucket/set-up-an-ssh-key-728138079.html

Theva
  • 873
  • 8
  • 15