Can';t为pip install git+;Github上的ssh

Can';t为pip install git+;Github上的ssh,git,github,ssh,pip,ssh-keys,Git,Github,Ssh,Pip,Ssh Keys,我似乎无法从github安装私有存储库,我很确定我已经将问题追溯到了密钥文件。复杂的因素是我的~/.ssh目录中有几十个密钥文件,当我试图指定一个特定的密钥文件时,它似乎不起作用。对于pip安装,不管我的语法如何,它都会选择第一个密钥文件 安装repo1有效,包括不存在此类密钥文件或指定了错误的密钥文件时: > pip install git+ssh://git@github.com/username/repo1.git > pip install --cert ~/.ssh/key

我似乎无法从github安装私有存储库,我很确定我已经将问题追溯到了密钥文件。复杂的因素是我的~/.ssh目录中有几十个密钥文件,当我试图指定一个特定的密钥文件时,它似乎不起作用。对于pip安装,不管我的语法如何,它都会选择第一个密钥文件

安装repo1有效,包括不存在此类密钥文件或指定了错误的密钥文件时:

> pip install git+ssh://git@github.com/username/repo1.git
> pip install --cert ~/.ssh/keyfile1 git+ssh://git@github.com/username/repo1.git
> pip install --cert ~/.ssh/keyfile1_BLAH_NO_SUCH_FILE git+ssh://git@github.com/username/repo1.git
> pip install --client-cert ~/.ssh/keyfile1 git+ssh://git@github.com/username/repo1.git
> pip install --client-cert ~/.ssh/keyfile1_BLAH_NO_SUCH_FILE git+ssh://git@github.com/username/repo1.git
> pip install --client-cert ~/.ssh/keyfile2 git+ssh://git@github.com/username/repo1.git
无论语法如何,安装repo2都不起作用:

> pip install git+ssh://git@github.com/username/repo2.git
> pip install --cert ~/.ssh/keyfile2 git+ssh://git@github.com/username/repo2.git
> pip install --client-cert ~/.ssh/keyfile2 git+ssh://git@github.com/username/repo2.git
通过执行以下操作,我可以验证密钥文件是否正确,以及Github是否能够识别:

> ssh -T git@github.com
Hi username/repo1! You've successfully authenticated, but GitHub does not provide shell access.

> ssh -T git@github.com -i ~/.ssh/keyfile1
Hi username/repo1! You've successfully authenticated, but GitHub does not provide shell access.

> ssh -T git@github.com -i ~/.ssh/keyfile2
Hi username/repo2! You've successfully authenticated, but GitHub does not provide shell access.
如果未指定或未正确指定密钥文件,我可以验证是否使用了keyfile1:

> ssh -T git@github.com -i ~/.ssh/keyfile1_BLAH_NO_SUCH_FILE
Warning: Identity file keyfile1_BLAH_NO_SUCH_FILE not accessible: No such file or directory.
Hi username/repo1! You've successfully authenticated, but GitHub does not provide shell access.

> ssh -T git@github.com
Hi username/repo1! You've successfully authenticated, but GitHub does not provide shell access.
所以我认为这告诉我keyfile2是好的

为了消除repo2出现问题的可能性,我将keyfile1移到github中的repo2,然后repo2是我可以pip安装的唯一存储库

因此,我的pip安装语法似乎只适用于第一个密钥文件,因为它首先找到了它,我或者错误地指定了密钥文件,或者忽略了我的规范

pip 20.2.4

有什么想法吗?

选项仅用于HTTPS,从未用于
git+ssh
协议
pip
实际上没有办法将SSH密钥传递给
git
。您必须通过配置
git
ssh
来传递它

你可以尝试使用

也可以使用环境变量并传递密钥:

GIT_SSH_COMMAND='ssh -i ~/.ssh/keyfile2' pip install git+ssh://git@github.com/username/repo2.git
截至今天(PIP19.3.1),pip安装使用ssh密钥开箱即用

ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
pip install git+ssh://git@github.com/username/myprivaterepo.git@branch

(假设密钥
~/.ssh/id\u rsa.pub
已经添加到github)

知道我没有做错什么非常有用。你认为这是一个合理的功能要求吗?我不介意帮助编写/测试它,但这将是我对广泛使用的开放源码python库的第一次贡献。因此,我可能需要有人保护我。“你认为这是一个合理的功能要求吗?”你可以试试。我无法预测
pip
作者的反应。他们可以决定配置
git
ssh
是传递密钥的方式。