无法克隆,可以 SSH。“权限被拒绝(公钥)。”

Ada*_*ele 3 windows git ssh git-credential-manager

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

我有一个裸存储库,它位于我尝试通过 访问的user@host目录中的一个目录。我曾经添加过我的 ssh 密钥。它要求我提供密码。然后我就可以成功了。home/user/test.gitgit clonessh-add <pathtokey>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.
Run Code Online (Sandbox Code Playgroud)

也尝试过

  • 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版本: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
  • PowerShell和shell都试过了git bash,结果一样
  • user具有存储库的读取、执行权限

Ada*_*ele 5

添加到 @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
Run Code Online (Sandbox Code Playgroud)

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

在此之后,它应该可以在 git-bash 以外的其他地方正常工作。在 Powershell-Core、命令提示符中确认

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