2

I have a private git repository on Gitea. I have set up the deploy key there for my server and on the server I have the relevant private key in C:\Users\harry\.ssh\id_ed25519

When I try to directly git clone the repo, it works OK:

(venv) harry@DESKTOP-4NS8B70 d:\>git clone "ssh://git@git.myserver.com/my_username/my_package.git" my_package    
Cloning into 'my_package'...
Enter passphrase for key '/c/Users/harry/.ssh/id_ed25519': 
remote: Enumerating objects: 52, done.
remote: Counting objects: 100% (52/52), done.
Receiving objects: 100% (52/52), 10.18 KiB | 5.09 MiB/s, done.
Resolving deltas:  95% (20/21)00% (45/45), done.
remote: Total 52 (delta 21), reused 0 (delta 0)
Resolving deltas: 100% (21/21), done.

So far, so good! However, when I try to install the very same package by pip install -e "git+ssh://git@git.myserver.com/my_username/my_package.git#egg=my_package" it results in an error:

(venv) harry@DESKTOP-4NS8B70 d:\>pip install -e "git+ssh://git@git.myserver.com/my_username/my_package.git#egg=my_package"
Obtaining my_package from git+ssh://****@git.myserver.com/my_username/my_package.git#egg=my_package
  Cloning ssh://****@git.myserver.com/my_username/my_package.git to d:\my_app\venv\src\my-package
  Running command git clone -q 'ssh://****@git.myserver.com/my_username/my_package.git' 'd:\my_app\venv\src\my-package'
  git@git.myserver.com: Permission denied (publickey).
  fatal: Could not read from remote repository.

  Please make sure you have the correct access rights
  and the repository exists.
WARNING: Discarding git+ssh://****@git.myserver.com/my_username/my_package.git#egg=my_package. Command errored out with exit status 128: git clone -q 'ssh://****@git.myserver.com/my_username/my_package.git' 'd:\my_app\venv\src\my-package' Check the logs for full command output.

Of course, the same thing happens when I try to pip install -r requirements.txt with the following entry

-e "git+ssh://git@git.myserver.com/my_username/my_package.git#egg=my_package"

My first thought is that the issue happens, because it somehow does not ask to Enter passphrase for key, but I have no idea why! Any ideas what else could have gone wrong?

jevgienij
  • 41
  • 1
  • 3
  • 1
    `pip` is non-interactive program and it prevents interactive subprocesses from interacting with the user. To resolve the problem you must configure `ssh` to avoid asking the passphrase; either remove the passphrase from the key or setup `ssh-agent`. – phd Jun 30 '21 at 18:25
  • That's really helpful! I connect to my server via SSH, so all I needed to do was to run `start-ssh-agent` in that SSH console. Then I was able to `pip install`. – jevgienij Jun 30 '21 at 20:59

1 Answers1

1

As commented, and described in Pip Installing a Package From a Private Repository from Fernando Freitas Alves, adding an ssh agent will allow your pip command to complete:

cd ~/.ssh
ssh-keygen -t rsa -b 4096 -C "dev@email.com"
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa

The alternative is to use an HTTPS URL:

git config --global url.https://github.com/.insteadOf git@github.com:

The same pip command would automatically used an HTTPS URL instead of the SSH one, assuming you have a credential manager caching your credentials.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • You probably missed out that the server runs on Windows, not on Linux ("on the server I have the relevant private key in `C:\Users\harry\.ssh\id_ed25519`"), so the first code block would not work for me. Instead, I had to ssh the server and run `start-ssh-agent` in the ssh console. The alternative of using an HTTPS URL would not work for me either, because as I said, my private repo is on Gitea, not on Github. And the gitea server I use forces me to use SSH connection. – jevgienij Jul 01 '21 at 11:56
  • @jevgienij As seen in https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent, this works on Windows too (in a Git bash session). And gitea in general can support HTTPS (I have one on premise at work). But not in your case indeed. – VonC Jul 01 '21 at 12:39
  • Yes, in a git bash session it works, but when I ssh to that PC I'm not in a git bash session, so I have to use `start-ssh-agent` instead. – jevgienij Jul 01 '21 at 12:45
  • @jevgienij Agreed (I just tested that case). These days, with a recent Windows 10, I am working in a WSL2 Linux session anyway, so the all Windows/Linux border tends to be a bit blurry. – VonC Jul 01 '21 at 12:56