2

I am trying to clone a private Git repo from npm inside a Docker container but am getting an error Permission denied (publickey).

I generated a SSH key with this command on my host machine:

ssh-keygen -t rsa -b 4096 -C "myname@mydomain.com"

Then I added this to Bitbucket, ssh-add-ed it, and tested it with git clone and everything worked fine (on the host machine). I also tried npm install in my project folder and all git cloning was fine.

I copied the id_rsa and id_rsa.pub files to another folder and I mount this folder to /root/.ssh when doing docker run. The problem now is that npm install gives a permission denied error when trying to clone from that private Git repo.

I went into the container with bash and tried npm install manually, but got the same error. I made sure that ssh-agent was up by running eval "$(ssh-agent -s)" and then made sure the key was added by running ssh-add ~/.ssh/id_rsa. Then I tried it again, but the same issue.

The thing though is that if, in the same container, I try just a regular git clone ... then it clones fine! No problems or anything. I know it is using the SSH key since if I remove it from Bitbucket, I get a permission denied error. Then if I re-add it to Bitbucket, it clones fine.

How do I get npm to clone properly? The working (inside the container) git clone command I use is:

git clone git@bitbucket.org:org/repo.git

and the npm repo dependency line is:

"repo": "git+ssh://bitbucket.org/org/repo.git"

The full npm error is:

npm ERR! git clone ssh://bitbucket.org/org/repo.git Cloning into bare repository '/root/.npm/_git-remotes/ssh-bitbucket-org-org-repo-git-3f459951'...
npm ERR! git clone ssh://bitbucket.org/org/repo.git Permission denied (publickey).
npm ERR! git clone ssh://bitbucket.org/org/repo.git fatal: Could not read from remote repository.
npm ERR! git clone ssh://bitbucket.org/org/repo.git 
npm ERR! git clone ssh://bitbucket.org/org/repo.git Please make sure you have the correct access rights
npm ERR! git clone ssh://bitbucket.org/org/repo.git and the repository exists.
shiznatix
  • 1,087
  • 1
  • 20
  • 37

1 Answers1

1

"git+ssh://bitbucket.org/org/repo.git" does not look like a valid ssh url.

"git+ssh://git@bitbucket.org/{user}/{repository}.git" is.

Check if you can change the npm repo dependency url.
(and/or npm install -S "git+https://username@github.com/orgname/repositoryname.git")

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • After all the searching, this is the correct answer. I just had to add "git@" before bitbucket in the URL and it was fine. Thank you! – shiznatix Dec 18 '15 at 17:20