【问题标题】:How do I provide SSH keys to GitHub Actions so that pip can install from a git repo? [duplicate]如何向 GitHub Actions 提供 SSH 密钥,以便 pip 可以从 git repo 安装? [复制]
【发布时间】:2021-09-29 21:11:07
【问题描述】:

我想在 GitHub Actions 作业中 pip install 来自私有 GitHub 存储库的库。我可以将它安装在我的计算机上,因为我已将 GitHub 配置为接受 SSH 密钥。但是如何将 SSH 密钥提供给 GitHub Actions 运行程序?

在我的电脑上,这工作正常:

python -m pip install "git+ssh://git@github.com/ORG/LIBRARY.git@main#egg=SOMETHING&subdirectory=SOMETHING"
Collecting LIBRARY
  Cloning ssh://****@github.com/ORG/LIBRARY.git (to revision main) to /tmp/pip-install-_kw52ce5/LIBRARY_35c4fb5cf6a64e30914beaec4a768bd1
  Installing build dependencies ... done
...
Successfully built LIBRARY-0.1.1

出于隐私考虑,我更改了图书馆、组织和目录的名称。来自 GitHub 存储库的 pip 安装文档是 here

我尝试了this 指南和this GitHub 操作,但没有成功。在 GitHub Actions 中,我收到以下错误消息:

Step 15/20 : RUN pip install -r requirements.txt
 ---> Running in 5ece3eb6572e
  Collecting LIBRARY@ git+ssh://git@github.com/ORG/LIBRARY.git@main#egg=SOMETHING&subdirectory=SOMETHING
  Cloning ssh://****@github.com/ORG/LIBRARY.git (to revision main) to /tmp/pip-install-ohx86p2h/LIBRARY_2972ab1296ce45afa73bbb3c5a036bd1
  Running command git clone -q 'ssh://****@github.com/ORG/LIBRARY.git' /tmp/pip-install-ohx86p2h/LIBRARY_2972ab1296ce45afa73bbb3c5a036bd1
  Host key verification failed.
  fatal: Could not read from remote repository.

  Please make sure you have the correct access rights
  and the repository exists.

如何将 SSH 密钥提供给 GitHub Actions 运行器?

【问题讨论】:

  • 不是一个完整的解决方案,但如果您有您的跑步者的公共 SSH 密钥(在指定的用户帐户上),您是否考虑将其添加到您的 GitHub 帐户的 SSH 密钥中?
  • 是的,我将公共 SSH 密钥设置为我尝试从 pip install 发送的存储库上的部署密钥。

标签: github ssh pip github-actions ssh-keys


【解决方案1】:

我认为“主机密钥验证失败”表明 ~/.ssh/known_hosts 文件存在问题。通常,当您第一次通过 ssh 连接到主机时,系统会提示您类似以下内容:

The authenticity of host 'domain.com (a.b.c.d)' can't be established.
RSA key fingerprint is XX:XX:...:XX.
Are you sure you want to continue connecting (yes/no)? 

当您回答“是”时,主机密钥会自动添加到 known_hosts 文件中。您可以手动将主机密钥添加到运行 Github 操作的用户的 known_hosts 文件中:

  1. 直接从 github 管理员或登录 github.com 获取主机密钥(更安全 - 强烈建议)。
  2. 使用ssh-keyscan -H github.com >> ~/.ssh/known_hosts

【讨论】:

    猜你喜欢
    • 2019-08-28
    • 2013-12-04
    • 1970-01-01
    • 2020-04-25
    • 1970-01-01
    • 2020-05-30
    相关资源
    最近更新 更多