git - 为什么我不能在 docker 中使用正确的 ssh key 克隆私有(private) git 存储库?

标签 git docker github ssh

我正在尝试 git clone使用 ssh 身份验证从 docker 容器内部到私有(private)存储库。我遵循了提出的解决方案 here .

为此,我创建了一个本地 key

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

并将公钥添加到 github SSH key 。然后在 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.

还有什么我可以检查的吗?

再次解释为什么:我希望能够使用 FIXED 私钥创建图像,该私钥始终与 github 上的公钥一起使用,因此我可以使用相同的图像,但能够将实际/当前存储库下载到正在运行的容器中.该镜像配备了正确的 key ,因此它可以访问 github 存储库,并且能够在从同一镜像启动包含的内容时下载当前存储库...
该图像用于 Selenium 测试,稍后将由脚本(或 Jenkins )自动执行,然后我无法“登录”到容器以创建 ssk key 对并将公钥上传到 github。整个过程是自动化测试。因此,必须将身份验证构建到图像中。

希望这现在很清楚。

最佳答案

由于您已经在 docker 容器中创建了 ssh key 。你需要做什么:

  • 登录到 docker 容器以复制生成的 ssh 公钥。
  • 然后,您需要将公钥添加到您的 github 帐户。

  • 之后,您可以轻松克隆私有(private) git 存储库。

    关于git - 为什么我不能在 docker 中使用正确的 ssh key 克隆私有(private) git 存储库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47221473/

    相关文章:

    git - 如何在 git 子模块更新和 checkout 后恢复丢失的提交?

    git - 如何在 Cygwin 终端中指定 git 路径?

    python - Flask + Docker 应用程序 - 当我运行 docker run 时容器死亡

    python - PyPI 安装和 tarball 中缺少我的包的 requirements.txt 文件

    jenkins - 创建拉取请求到分支时,Github 不触发作业

    visual-studio - VS2013 with GitHub - 停止由提交的 typescript 文件制作的 JS 文件

    git - 列出 Git LFS 未跟踪的文件

    适用于 Mac OS X 10.4 的 Git

    docker - 如何将容器从一个节点移动到另一个节点?

    amazon-web-services - docker + Jenkins + AWS