【问题标题】:Cannot clone remote git repo via ssh无法通过 ssh 克隆远程 git repo
【发布时间】:2021-11-07 06:50:24
【问题描述】:

新安装的Windows 11,使用ssh-keygen -t rsa -C "my@email.com"命令创建密钥对并将id_rsa.pub文件中的内容上传到git服务器,然后在windows terminal powershell中运行git clone git@server:user/repo,然后我得到了权限拒绝

  • 我已经确认我上传的公钥是正确的,私钥文件可以从git bashcygwin terminalwindows terminal powershell正确访问。

  • 我试图删除密钥对并重新生成一个然后上传,这是无奈的。

  • 我尝试更改了一个git服务器,包括coding.netgitee.comgithub.com,报告都是一样的。(Permission denied

  • 我确认远程 git repo 存在。

  • 我确认我可以通过 https 和用户名密码身份验证正确访问 git repo。

  • 我尝试在我的 mac 或 linux 上克隆 repo,它们没问题。

我在这个网站上搜索了一些帖子后,我尝试了ssh -v git@gitee.com,然后得到了以下报告:

OpenSSH_for_Windows_8.1p1, LibreSSL 3.0.2
debug1: Connecting to gitee.com [212.64.62.183] port 22.
debug1: Connection established.
debug1: identity file C:\\Users\\ye/.ssh/id_rsa type 0
debug1: identity file C:\\Users\\ye/.ssh/id_rsa-cert type -1
debug1: identity file C:\\Users\\ye/.ssh/id_dsa type -1
debug1: identity file C:\\Users\\ye/.ssh/id_dsa-cert type -1
debug1: identity file C:\\Users\\ye/.ssh/id_ecdsa type -1
debug1: identity file C:\\Users\\ye/.ssh/id_ecdsa-cert type -1
debug1: identity file C:\\Users\\ye/.ssh/id_ed25519 type -1
debug1: identity file C:\\Users\\ye/.ssh/id_ed25519-cert type -1
debug1: identity file C:\\Users\\ye/.ssh/id_xmss type -1
debug1: identity file C:\\Users\\ye/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_for_Windows_8.1
debug1: Remote protocol version 2.0, remote software version ssh-pilot-1.1.1
debug1: no match: ssh-pilot-1.1.1
debug1: Authenticating to gitee.com:22 as 'git'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: ssh-ed25519
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ssh-ed25519 SHA256:+ULzij2u99B9eWYFTw1Q4ErYG/aepHLbu96PAUCoV88
debug1: Host 'gitee.com' is known and matches the ED25519 host key.
debug1: Found key in C:\\Users\\ye/.ssh/known_hosts:1
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 134217728 blocks
debug1: pubkey_prepare: ssh_get_authentication_socket: No such file or directory
debug1: Will attempt key: C:\\Users\\ye/.ssh/id_rsa RSA SHA256:vjf1QWcO+923/akAbAnZybgl+L9eJBDDTDtKyqvXdkA
debug1: Will attempt key: C:\\Users\\ye/.ssh/id_dsa
debug1: Will attempt key: C:\\Users\\ye/.ssh/id_ecdsa
debug1: Will attempt key: C:\\Users\\ye/.ssh/id_ed25519
debug1: Will attempt key: C:\\Users\\ye/.ssh/id_xmss
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: C:\\Users\\ye/.ssh/id_rsa RSA SHA256:vjf1QWcO+923/akAbAnZybgl+L9eJBDDTDtKyqvXdkA
debug1: Server accepts key: C:\\Users\\ye/.ssh/id_rsa RSA SHA256:vjf1QWcO+923/akAbAnZybgl+L9eJBDDTDtKyqvXdkA
debug1: Authentication succeeded (publickey).
Authenticated to gitee.com ([212.64.62.183]:22).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: pledge: network
debug1: ENABLE_VIRTUAL_TERMINAL_INPUT is supported. Reading the VTSequence from console
debug1: ENABLE_VIRTUAL_TERMINAL_PROCESSING is supported. Console supports the ansi parsing
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
Hi Lagom! You've successfully authenticated, but GITEE.COM does not provide shell access.
debug1: channel 0: free: client-session, nchannels 1
Connection to gitee.com closed.
Transferred: sent 3084, received 1512 bytes, in 0.2 seconds
Bytes per second: sent 15886.8, received 7788.8
debug1: Exit status 0

我似乎有权访问 git 服务器,但这是我重新运行git clone 命令后收到的内容。

PS D:\Workspace> git clone git@gitee.com:username/demo-repo.git
Cloning into 'demo'...
git@gitee.com: Permission denied (publickey).
fatal: Could not read from remote repository.

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

我该怎么做才能使它正确?

【问题讨论】:

  • 这能回答你的问题吗? ssh "permissions are too open" error
  • 我发现了这个问题并解决了,现在帖子已经更新了。但我还是得到了git@gitee.com: Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
  • Gitee 现在需要非 RSA 密钥;使用 RSA 密钥进行 ssh 测试似乎很奇怪。 (事实上​​,Windows 和 Git-for-Windows 内部也有相互竞争的 ssh 实现,这有时会导致这里出现问题,但我认为它不应该导致这个特定的问题。)
  • @torek 这说不通,不光是gitee,还有github、gitlab、coding和所有git服务器都报Permission denied,难道所有服务器都不支持rsa key了吗?
  • OpenSSH 有一个更新,默认情况下拒绝短 RSA 密钥。当每个人都更新到最新版本时,他们就会停止工作。这不是一下子完成的,但速度相当快。 (这并不意味着这问题,但这是一种可能性。)

标签: git ssh


【解决方案1】:

你好用户名!您已成功通过身份验证,但 GITEE.COM 不提供 shell 访问权限。

您的密钥适用于基本身份验证,但您仍然无法克隆 username/demo-repo.git(假设“username”与 Hi username! 消息中的相同)

正如我mentioned before,您可能需要创建一个 ed25519 密钥:

cd %USERPROFILE%\.ssh
ssh-keygen -t ed25519 -C  "xxxxx@xxxxx.com"  -P "" -f gitee

还有一个%USERPROFILE%\.ssh\config

Host gitee
  Hostname gitee.com
  User git
  Identityfile ~/.ssh/gitee

最后:git clone gitee:username/demo-repo.git(没有git@gitee.com,只有gitee

【讨论】:

  • 感谢您的帮助,问题解决了,但让我困惑的是为什么会出现这个问题?你能解释一下为什么吗?
  • @vorbote gitee 可能不再授权 rsa 密钥进行克隆。只有ed25519。因此他们的官方文件; gitee.com/help/articles/4181
  • 我认为这不应该发生,似乎不可能在coding.net、gitee或github上使用rsa密钥对。昨晚我尝试了这 3 个 git 站点,它们都报告给我的 mac/linux 并且我的 windows 的权限被拒绝。
  • @vorbote 那你可能需要询问 gitee 支持。我假设这是一个 mainlang 中国限制。
猜你喜欢
  • 2018-08-24
  • 2013-08-07
  • 2018-11-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-18
相关资源
最近更新 更多