windows - 无法克隆,可以 SSH。 "Permission denied (publickey)."

标签 windows git ssh git-credential-manager

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

我有一个裸仓库位于一个目录 user@host在目录 home/user/test.git我正在尝试通过 git clone 访问.我用了ssh-add <pathtokey>添加我的 ssh key 。它问我密码。然后我可以 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 凭据管理器没有提取 key ?

在服务器上/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
  • 都试过了PowerShellgit bash炮弹,同样的结果
  • user对仓库有读取、执行权限

最佳答案

添加到@VonC 的回复中

在 git-bash 中一切正常。

启动ssh-agent的正常流程(通过 eval 'ssh-agent' ), 通过 ssh-add <path_to_key> 添加 key 启用 git clone去工作。

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

ssh-agent自动启动(假设您之前启动了 OpenSSH Authentication Agent 服务),添加 key 有效,您可以 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

关于windows - 无法克隆,可以 SSH。 "Permission denied (publickey).",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66287406/

相关文章:

c# - Aforge.Video库的MJPEGStream函数示例

c++ - 带有控制台输出的 Qt GUI 应用程序 - 在 Windows 上正常启动时隐藏控制台

git - git fetch不起作用-但 checkout 有效

bash - SSH 时为新主机自动执行 "yes"

c - 在 Windows shell 命令中嵌入 Python 代码

windows - CD到目录,路径在文件中

git - 是否可以使用 Ansible 在没有 "git submodule update"或 "command:"的情况下执行 "shell:"?

git - 为什么一个简单的 `git mv` 会失败?

git - 有没有人在 z/OS R2.4 上为 git clone 提供有效的 Jenkins 代理配置

ssh - Bamboo-SSH任务中SCP调用的正确格式