为什么我不能在Docker中使用正确的ssh密钥克隆一个私人的git仓库?

我正在尝试使用ssh身份validation从docker容器内克隆到私有存储库。 我遵循这里提出的解决scheme。

为此,我创build了一个本地密钥

 ssh-keygen -q -t rsa -N '' -f repo-key 

并将公钥添加到github ssh密钥。 然后在Dockerfile中我添加了:

 RUN chmod 600 repo-key && \ echo "IdentityFile /selenium/repo-key" >> /etc/ssh/ssh_config && \ echo "StrictHostKeyChecking no" >> /etc/ssh/ssh_config 

但是当我试图git clone一个存储库,我得到了错误信息

 Permission denied (publickey,gssapi-keyex,gssapi-with-mic). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. 

还有什么我可以检查,使这项工作?

再次解释为什么:我想能够创build图像与固定的私钥总是与github上的公钥一起工作,所以我可以使用相同的图像,但能够下载实际/当前的存储库到正在运行的容器。 该图像配备了正确的密钥,所以它有权访问github存储库,并能够下载当前的存储库,当一个包含从相同的图像启动时…该图像是seleniumtesting,这将稍后自动执行脚本(或jenkins),然后我不能'login'容器来创build一个ssk密钥对,并将公钥上传到github。 整个事情就是自动化testing。 因此,authentication必须build立在形象。

HOPEFULLY现在已经很清楚了。

由于您已经在Docker容器中创build了一个ssh密钥。 你需要做什么:

  • login到docker容器中复制生成的ssh公钥。
  • 您需要将公钥添加到您的github帐户。

之后,你可以轻松地克隆私人git回购。

克隆一个GitHub仓库时,你仍然需要指定正确的用户来build立这个SSH连接: git

所以:

  git clone git@github.com:User/repo.git ^^^^^