无法克隆,但可以SSH。出现“Permission denied (publickey)”错误提示。

3
我无法克隆或推送到我的服务器上的存储库。我有一个裸仓库,位于目录home/user/test.git中的目录user@host中, 我正在尝试通过git clone访问它。我使用ssh-add 来添加我的ssh密钥。它要求我输入密钥密码。然后我可以成功地使用ssh user@host。但是如果我尝试git clone ssh://user@host/~/test.git,则会出现以下错误:
Cloning into 'test'...
user@host: Permission denied (publickey).
fatal: Could not read from remote repository.

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

同样的步骤我也尝试过:

  • git clone ssh://user@host/home/user/test.git
  • git clone user@host:home/user/test.git
  • git clone user@host:/home/user/test.git

但都没有成功。

我猜测是 Git 凭证管理器没有识别到密钥?

服务器上的 /var/auth/log 日志显示为:

Feb 20 02:25:36 xxxxx sshd[24674]: Connection closed by authenticating user XXXX x.x.x.x port 56433 [preauth]
  • Git 版本信息:git version 2.30.1.windows.1
  • Git 凭证管理器版本信息:Git Credential Manager version 2.0.318-beta+44acfafa98 (Windows, .NET Framework 4.0.30319.42000)
  • git config -l 命令返回的是 credential.helper=manager-core
  • 我尝试在 PowerShellgit bash Shell 中执行命令,但结果相同
  • user 对该仓库具有读、执行权限
2个回答

5

补充@VonC的回答:

在git-bash中,一切都像正常一样。

通过eval 'ssh-agent'启动ssh-agent,通过ssh-add <path_to_key>添加密钥,使得git clone能够工作。

在PowerShell Core或Cmd中,需要更多的工作,可以通过Windows-Terminal来实现。

ssh-agent会自动启动(假设您之前已经启动了OpenSSH Authentication Agent服务),添加密钥后,您可以ssh,但最初git命令不起作用,但如果您执行以下操作:

git config --global core.sshCommand C:/Windows/System32/OpenSSH/ssh.exe

这将使用Windows10的实现替换git-for-windows附带的(默认)ssh。

替换后,除了git-bash之外的其他内容应该都可以正常工作。在Powershell-Core、命令提示符中已确认。

另请参阅:https://gist.github.com/danieldogeanu/16c61e9b80345c5837b9e5045a701c99


这绝对解决了我的问题,谢谢! - Maël Pedretti

1
Git凭证管理器仅用于缓存HTTPS URL的凭证(用户名/密码),而不是SSH。
只有ssh-agent可能会涉及到,用于缓存可能的口令,如果私钥是用它定义的。
我建议首先尝试使用完整路径,因为“~”可能无法被远程shell解释,但本地shell可以(对于“~”有不同的路径)。
git clone ssh://user@host/home/user/test.git
# or
git clone user@host:/home/user/test.git

如果不是在 Git Bash 会话中,请键入:

export GIT_SSH_COMMAND='ssh -v'
git clone ...

楼主在讨论中确认它可以在bash会话中工作:

在git bash中,我启动了ssh-agent
将密钥添加到其中,然后它就可以工作了。


在绝对路径上得到相同的结果。 - Adam V. Steele
1
@AdamV.Steele 你有以GIT_SSH开头的任何环境变量吗?你的私钥是ppk格式(putty)还是pem/openssh格式(使用ssh-keygen生成的)? - VonC
@AdamV.Steele 我也建议尝试使用 git clone user@host:/home/user/test.git - VonC
我可以正常使用 ssh。只有 git 命令失败了。我没有任何以 GIT_SSH 开头的变量。这是一个 OpenSSH 密钥。 - Adam V. Steele
@AdamV.Steele 好的。你确认 git clone user@host:/home/user/test.git 也不起作用吗? - VonC
显示剩余2条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接