1

我在 Gitea 上有一个私人 git 存储库。我已经为我的服务器设置了部署密钥,并且在服务器上我有相关的私钥C:\Users\harry\.ssh\id_ed25519

当我尝试直接git clone回购时,它可以正常工作:

(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.

到目前为止,一切都很好!但是,当我尝试通过它安装相同的软件包时pip install -e "git+ssh://git@git.myserver.com/my_username/my_package.git#egg=my_package"会导致错误:

(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.

当然,当我尝试pip install -r requirements.txt使用以下条目时也会发生同样的事情

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

我的第一个想法是问题发生了,因为它以某种方式不要求Enter passphrase for key,但我不知道为什么!任何想法还有什么可能出错的?

4

1 回答 1

0

正如评论和描述的, Pip从Fernando Freitas Alves的私人存储库安装软件包,添加 ssh 代理将允许您的 pip 命令完成:

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

另一种方法是使用 HTTPS URL:

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

假设您有一个凭证管理器缓存您的凭证,相同的 pip 命令将自动使用 HTTPS URL 而不是 SSH URL。

于 2021-07-01T06:13:20.603 回答