【问题标题】:Can't clone, can SSH. "Permission denied (publickey)."不能克隆,可以SSH。 “权限被拒绝(公钥)。”
【发布时间】:2021-02-20 02:28:41
【问题描述】:

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

我有一个裸仓库,它位于目录home/user/test.git 中的一个目录user@host,我正试图通过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 版本: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 拥有 repo 的读取、执行权限

【问题讨论】:

    标签: windows git ssh git-credential-manager


    【解决方案1】:

    添加到@VonC 的回复

    在 git-bash 中一切正常。

    启动ssh-agent的正常流程(通过eval 'ssh-agent' ),通过ssh-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

    【讨论】:

      【解决方案2】:

      git 凭据管理器仅用于缓存 HTTPS URL 的凭据(用户名/密码),而不是 SSH。
      如果使用它定义了私钥,则只有 ssh-agent 可以用于缓存可能的密码。

      我会先尝试使用完整路径,因为~ 可能不会被远程 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 ...
      

      OP 确认 in the discussion 它在 bash 会话中工作:

      在 git bash 中,我启动了ssh-agent
      在那里添加了密钥,然后它就起作用了。

      【讨论】:

      • 绝对路径上的结果相同
      • @AdamV.Steele 你有任何以 GIT_SSH 开头的环境变量吗?你的私钥是 ppk 一种(腻子)还是 pem/openssh 一种(使用ssh-keygen 制作)?
      • @AdamV.Steele 我也想试试git clone user@host:/home/user/test.git
      • 我可以ssh 很好。只有 git 命令失败。我没有任何以GIT_SSH 开头的变量。它是一个 OpenSSH 密钥
      • @AdamV.Steele 好的。你确认git clone user@host:/home/user/test.git也不起作用?
      猜你喜欢
      • 2016-02-20
      • 2019-11-24
      • 2014-11-08
      • 2019-03-11
      • 1970-01-01
      • 1970-01-01
      • 2013-12-25
      • 1970-01-01
      • 2019-03-08
      相关资源
      最近更新 更多