1

我无法克隆或推送到服务器上的存储库。

我有一个裸仓库,它位于user@hosthome/user/test.git试图通过git clone. 我曾经ssh-add <pathtokey>添加我的 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/logFeb 20 02:25:36 xxxxx sshd[24674]: Connection closed by authenticating user XXXX x.x.x.x port 56433 [preauth]

  • 吉特版本: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 bashshell,结果相同
  • user已读取、执行 repo 的权限
4

2 回答 2

2

添加到@VonC 的回复

在 git-bash 中一切正常。

ssh-agent启动(via )的正常流程eval 'ssh-agent' ,添加密钥 viassh-add <path_to_key>可以git clone工作。

在 PowerShell Core 或 Cmd 中,需要通过 Windows 终端进行更多工作

自动启动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

于 2021-02-20T03:15:23.393 回答
1

The git credential manager is only involved for caching credentials (username/password) for HTTPS URL, not SSH.
Only the ssh-agent could be involved, for caching a possible passphrase, if the private key was defined with it.

I would try first using the full path, since ~ might not be interpreted by the remote shell, but the local (which has a different path for ~):

git clone ssh://user@host/home/user/test.git
# or
git clone user@host:/home/user/test.git

If not, in a git bash session, type:

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

The OP confirms in the discussion it works in a bash session:

In git bash, I started the ssh-agent,
added the key there, then it worked.

于 2021-02-20T02:31:17.773 回答