ssh-agent 或 git 配置或 github 或任何其他原因的问题

Problem with ssh-agent, or git config, or github, or any other reason

所以我正在尝试通过 ssh 克隆我的存储库。

为此,我有:

最后,当我尝试 git clone .. 我的远程仓库时出现错误:

git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

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

P.S GitHub 关于“权限被拒绝”主题的常见问题解答对我没有任何帮助。

编辑:

ssh -vT git@github.com

OpenSSH_for_Windows_7.7p1, LibreSSL 2.6.5
debug1: Connecting to github.com [140.82.118.3] port 22.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file C:\Users\.../.ssh/id_rsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\Users\.../.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\Users\.../.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\Users\.../.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\Users\.../.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\Users\.../.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\Users\.../.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\Users\.../.ssh/id_ed25519-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\Users\.../.ssh/id_xmss type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\Users\.../.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_for_Windows_7.7
debug1: Remote protocol version 2.0, remote software version babeld-5a455904
debug1: no match: babeld-5a455904
debug1: Authenticating to github.com:22 as 'git'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: rsa-sha2-512
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-rsa SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8
debug1: Host 'github.com' is known and matches the RSA host key.
debug1: Found key in C:\Users\.../.ssh/known_hosts:4
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-rsa,rsa-sha2-512,rsa-sha2-256,ssh-dss>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: RSA SHA256:LsIWcaAcRR0Lh880/ImF1Ex9doM47aqEqt9rXcl3BTE c:/users/.../.ssh/github/key
debug1: Server accepts key: pkalg ssh-rsa blen 535
warning: agent returned different signature type ssh-rsa (expected rsa-sha2-512)
debug1: Authentication succeeded (publickey).
Authenticated to github.com ([140.82.118.3]:22).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: pledge: network
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
Hi Nickpofig! You've successfully authenticated, but GitHub does not provide shell access.
debug1: channel 0: free: client-session, nchannels 1
Transferred: sent 3328, received 2484 bytes, in 0.2 seconds
1
s

您可以输入:

set "GIT_SSH_COMMAND=ssh -Tv"
git clone git@github.com:<me>/<myrepo>

您将看到发生了什么,特别是如果您的 %USERPROFILE%\.ssh\id_rsa 密钥被使用。

这类似于 ssh -Tv git@github.com(如末尾所述 .com

好的,问题是我的系统特有的,所以你无法提供帮助,不过,还是谢谢你。在研究了 GIT_SSH_COMMAND 是什么之后,我发现 git 使用它来将用户应用程序设置为 ssh 通信的建立者。在我的例子中,我没有在我的环境中列出该变量,所以我通过命令行手动添加了“GIT_SSH”(也适用于 git):setx GIT_SSH C:/WINDOWS/System32/OpenSSH/ssh.exe。为了以防万一,通过命令检查 ssh.exe 的路径:Get-Command ssh(Get-Command 只是给你给定环境变量的路径)并将其放在 GIT_SSH 之后(你的新的环境变量,git 将使用它来建立 ssh 通信)。就是这样。

请注意,不要只使用 set 命令 - 它只会为当前终端会话添加一个变量,因此在我们的例子中没有用。

当然,您克隆 git 存储库的问题可能有不同的根。但是,如果您检查设置的“GIT_SSH”变量,这将消除您遇到的问题。