Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't Specify keyfile for pip install git+ssh on Github

I can't seem to pip install a private repository from github, and I'm pretty sure I've traced the problem to the key file. The complicating factor is that I have dozens of keyfiles in my ~/.ssh directory, and it doesn't seem to work when I try to specify a specific keyfile. For pip install, it's choosing the first keyfile regardless of my syntax.

Installing repo1 works, including when no such key file exists or if the wrong keyfile is specified:

> pip install git+ssh://[email protected]/username/repo1.git
> pip install --cert ~/.ssh/keyfile1 git+ssh://[email protected]/username/repo1.git
> pip install --cert ~/.ssh/keyfile1_BLAH_NO_SUCH_FILE git+ssh://[email protected]/username/repo1.git
> pip install --client-cert ~/.ssh/keyfile1 git+ssh://[email protected]/username/repo1.git
> pip install --client-cert ~/.ssh/keyfile1_BLAH_NO_SUCH_FILE git+ssh://[email protected]/username/repo1.git
> pip install --client-cert ~/.ssh/keyfile2 git+ssh://[email protected]/username/repo1.git

Installing repo2 doesn't work, regardless of syntax:

> pip install git+ssh://[email protected]/username/repo2.git
> pip install --cert ~/.ssh/keyfile2 git+ssh://[email protected]/username/repo2.git
> pip install --client-cert ~/.ssh/keyfile2 git+ssh://[email protected]/username/repo2.git

I can verify the key files are correct and recognized by Github by doing this:

> ssh -T [email protected]
Hi username/repo1! You've successfully authenticated, but GitHub does not provide shell access.

> ssh -T [email protected] -i ~/.ssh/keyfile1
Hi username/repo1! You've successfully authenticated, but GitHub does not provide shell access.

> ssh -T [email protected] -i ~/.ssh/keyfile2
Hi username/repo2! You've successfully authenticated, but GitHub does not provide shell access.

I can verify that keyfile1 is used if a key file is not specified or specified incorrectly:

> ssh -T [email protected] -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 [email protected]
Hi username/repo1! You've successfully authenticated, but GitHub does not provide shell access.

So I think this tells me keyfile2 is good.

And to eliminate the possibility of there being a problem with repo2, I moved the keyfile1 over to repo2 in github and repo2 was then the only repository that I could pip install.

So, it appears as though my pip install syntax only works for the first keyfile because it find it first, and I'm either incorrectly specifying the keyfile or my specification is being ignored.

pip 20.2.4

Any ideas?

like image 937
Jonathan Avatar asked Oct 29 '25 05:10

Jonathan


1 Answers

Options --cert and --client-cert are used only for HTTPS and never used for git+ssh protocol. pip actually doesn't have a way to pass an SSH key to git. You have to pass it by configuring git or ssh.

You can try to use the trick with multiple Github accounts in ~/.ssh/config.

Or you can use GIT_SSH_COMMAND environment variable and pass the key:

GIT_SSH_COMMAND='ssh -i ~/.ssh/keyfile2' pip install git+ssh://[email protected]/username/repo2.git
like image 142
phd Avatar answered Oct 31 '25 20:10

phd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!