我正在尝试从Docker容器中的npm克隆私有Git repo,但收到错误Permission denied (publickey)
。
我在主机上使用此命令生成了一个SSH密钥:
ssh-keygen -t rsa -b 4096 -C "myname@mydomain.com"
然后我将其添加到Bitbucket,ssh-add
- 编辑它,并使用git clone
进行测试,一切正常(在主机上)。我还在我的项目文件夹中尝试了npm install
,并且所有git克隆都很好。
我将id_rsa
和id_rsa.pub
文件复制到另一个文件夹,然后在执行/root/.ssh
时将此文件夹挂载到docker run
。现在的问题是npm install
在尝试从该私有Git仓库进行克隆时给出了权限被拒绝错误。
我使用bash进入容器并手动尝试npm install
,但出现了同样的错误。我通过运行ssh-agent
确保eval "$(ssh-agent -s)"
已启动,然后确保通过运行ssh-add ~/.ssh/id_rsa
添加了密钥。然后我再次尝试了,但同样的问题。
但事情是,如果在同一个容器中,我只尝试一个普通的git clone ...
,那么它就克隆得很好!没问题或任何事情。我知道它正在使用SSH密钥,因为如果我从Bitbucket中删除它,我会收到权限被拒绝错误。然后,如果我将它重新添加到Bitbucket,它就克隆得很好。
如何让npm正确克隆?我使用的工作(在容器内)git clone命令是:
git clone git@bitbucket.org:org/repo.git
和npm repo依赖行是:
"repo": "git+ssh://bitbucket.org/org/repo.git"
完整的npm错误是:
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.
答案 0 :(得分:1)
“git+ssh://bitbucket.org/org/repo.git
”看起来不像是有效的ssh网址。
“git+ssh://git@bitbucket.org/{user}/{repository}.git
”是。
检查您是否可以change the npm repo dependency url
(和/或npm install -S "git+https://username@github.com/orgname/repositoryname.git"
)