【问题标题】:Git permission denied inside Docker containerDocker容器内的Git权限被拒绝
【发布时间】:2018-10-31 19:16:01
【问题描述】:

我使用 shell 脚本作为 Jenkinsfile 的一部分来运行数据库迁移。在 known_hosts 文件中设置条目后,shell 脚本会尝试克隆存储库。我正在做以下事情:

    #!/bin/bash

    set -e

    # Workaround old docker images with incorrect $HOME
    # check https://github.com/docker/docker/issues/2968 for details
    if [ "${HOME}" = "/" ]
    then
      export HOME=$(getent passwd $(id -un) | cut -d: -f6)
    fi

    mkdir -p ~/.ssh

    echo '
    github.com ssh-rsa KEY
  ' >> ~/.ssh/known_hosts

    git clone git@github.com:Organization/migrations.git /tmp/database-migrations

   Execute Migration

这给了我一个错误

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

如何解决这个问题?

顺便说一句,当我检查已知主机文件时,我看到一个条目已添加到文件中,其 IP 为192 范围(本地 IP)。这会造成问题吗?

【问题讨论】:

    标签: git shell docker jenkins ssh


    【解决方案1】:

    不是因为 known_hosts 文件。正如它所说,我认为这是你的私钥。

    您是否将正确的私钥复制到您的容器中?因为我没有在你的脚本中看到它。

    您可以通过键入以下内容来测试您的密钥:

    ssh -T git@github.com
    

    我相信您会看到相同的结果。

    您可以在 github 上查看此链接 Error: Permission denied (publickey)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-06
      • 2022-01-12
      • 2018-12-15
      • 2023-03-22
      • 2021-07-30
      • 2021-04-07
      • 1970-01-01
      • 2020-11-02
      相关资源
      最近更新 更多