【问题标题】:How to discover where 'pip install git+ssh://...' is searching for ssh keys?如何发现“pip install git+ssh://...”在哪里搜索 ssh 密钥?
【发布时间】:2021-01-04 22:31:15
【问题描述】:

问题:

有谁知道是否有一种简单的方法可以发现 pip install git+ssh:///... 在哪里搜索 ssh 密钥?

快速背景(已解决...请参阅下面的更新):

我在 Windows 10 上。我需要在 conda 虚拟环境中使用 pip 从 github 安装一个私有远程存储库。我是回购所有者。我通过 github.com 设置了一个公有/私有 ssh 密钥对。我的本地密钥存储在C:\Users\MyName\\.ssh\id_rsa。使用此密钥,我可以使用我的 IDE Eclipse 从 github 毫无问题地进行推送和拉取。

但是,当我使用激活的 conda 环境执行以下命令时:

pip install git+ssh://github.com/USER_NAME/REPO_NAME.git

我收到以下错误:

Collecting git+ssh://github.com/USER_NAME/REPO_NAME.git
Cloning ssh://github.com/USER_NAME/REPO_NAME.git to
c:\users\USER_NAME\appdata\local\temp\pip-ghf3ts-build
Warning: Permanently added 'github.com,IP_ADDRESS' (RSA) to the list of
known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.

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

我知道 repo 存在,并且我知道 ssh 密钥可以正常工作;所以,我假设 pip 调用的任何 ssh 例程都没有正确配置。

更新

从那以后我已经解决了这个问题,“错误配置”的假设被证明是正确的!我向 C:\Users\MyName\.ssh 添加了一个配置文件,指定要使用的文件。 Wham-bam,现在效果很好。

但是!我仍然有兴趣知道是否有任何确认 pip 正在该目录中查找 ssh 密钥和配置;所以,我暂时不考虑这个问题。

【问题讨论】:

    标签: python bash git ssh pip


    【解决方案1】:

    要在具有多个 ssh 密钥的项目中进行部署,请执行以下操作:

    $ export GIT_SSH_COMMAND="ssh -i ~/.ssh/deploy_key_1"
    $ pip install git+ssh://git@<my_hosted_gitlab>/project_with_deploy_key_1
    $ export GIT_SSH_COMMAND="ssh -i ~/.ssh/deploy_key_2"
    $ pip install git+ssh://git@<my_hosted_gitlab>/project_with_deploy_key_2
    

    它可以集成到 CI 过程中。

    【讨论】:

    • 仅供参考,GIT_SSH_COMMAND 在 Centos 7 上不可用。
    【解决方案2】:

    GIT_SSH_COMMAND 环境变量可以覆盖 Git 用来运行 ssh 的命令。在这种情况下,您希望启用详细输出。在 Windows 上,这看起来像:

    set GIT_SSH_COMMAND=ssh -v
    

    然后当你运行pip install git+ssh://github.com/USER_NAME/REPO_NAME.git 时,ssh 会输出调试信息,包括它在哪里寻找密钥:

    ...
    debug1: Reading configuration data /etc/ssh/ssh_config
    debug1: Connecting to github.com [192.30.253.112] port 22.
    debug1: Connection established.
    debug1: key_load_public: No such file or directory
    debug1: identity file /c/Users/MyName/.ssh/id_rsa type -1
    debug1: key_load_public: No such file or directory
    debug1: identity file /c/Users/MyName/.ssh/id_rsa-cert type -1
    debug1: key_load_public: No such file or directory
    debug1: identity file /c/Users/MyName/.ssh/id_dsa type -1
    debug1: key_load_public: No such file or directory
    debug1: identity file /c/Users/MyName/.ssh/id_dsa-cert type -1
    debug1: key_load_public: No such file or directory
    ...
    

    【讨论】:

      【解决方案3】:

      如果您没有机会使用 GIT_SSH_COMMAND 环境变量(例如,在 Centos 7 上不可用),您可以尝试在复制之前重命名 ssh-keys 的“dirty hack”。这不是好方法,但有效。

      我的“错误代码”:

      mv /var/www/.ssh/id_rsa /var/www/.ssh/id_rsa.tmp
      mv /var/www/.ssh/id_rsa_git /var/www/.ssh/id_rsa
      mv /var/www/.ssh/id_rsa.pub /var/www/.ssh/id_rsa.pub.tmp
      
      $VENV/bin/pip install --no-deps --editable "git+${REPO}@master#egg=web_bb_app"
      $VENV/bin/pip install -r $VENV/src/web-bb-app/requirements/${BRANCH}_branch_ssh.txt
      
      mv /var/www/.ssh/id_rsa /var/www/.ssh/id_rsa_git
      mv /var/www/.ssh/id_rsa.tmp /var/www/.ssh/id_rsa
      mv /var/www/.ssh/id_rsa.pub.tmp /var/www/.ssh/id_rsa.pub
      

      【讨论】:

        【解决方案4】:

        我已将 ssh 替换为 https,并且在 '@' 之前提到了用户名而不是 git:

        旧版本:

        pip install git+ssh://git@github.com/measureprotocol/measure-commons.git@v0.1.1#egg=measurecommons
        

        修改后的解决方案:

        pip install git+https://abhay-kiwi@github.com/measureprotocol/measure-commons.git@v0.1.1#egg=measurecommons
        

        【讨论】:

        • 这没有回答问题(即“pip git 在哪里查找 ssh 密钥”)。
        • 私有仓库也已经过时了,因为 github 禁用了 https 身份验证。 github.blog/…
        猜你喜欢
        • 2016-12-15
        • 2021-03-02
        • 2012-06-21
        • 2012-07-20
        • 1970-01-01
        • 1970-01-01
        • 2015-11-16
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多