微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Github ssh-agent 无法推送

如何解决Github ssh-agent 无法推送

我想通过 SSH 将更改推送到我的 git 存储库。

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.

我的 ssh-agent 已启动并正在运行。我通过 ssh-add 加载了我的密钥。这是正确的键,我检查了很多次。也在我的github上注册了。

当我尝试 git push origin 时,出现上述错误。这是正确的起源。

我也研究了很多,有人说如果同一个 git 有多个键,它会变得混乱或什么的,但我只加载了一个键。

我也通过 ssh 克隆了 repo。

我该怎么办?我被困在这 4 个多小时,我无法弄清楚。

更新

我已经运行了 ssh -v -T git@github.com 并且输出是:

OpenSSH_for_Windows_7.7p1,LibreSSL 2.6.5
debug1: Connecting to github.com [140.82.121.3] port 22.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\s/.ssh/id_rsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\s/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\s/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\s/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\s/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\s/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\s/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\s/.ssh/id_ed25519-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\s/.ssh/id_xmss type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\s/.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-b5f98373
debug1: no match: babeld-b5f98373
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:foobar
debug1: Host 'github.com' is kNown and matches the RSA host key.
debug1: Found key in C:\\Users\\foobar/.ssh/kNown_hosts:1
Warning: Permanently added the RSA host key for IP address 'foobar' to the list of kNown hosts.
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-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp256-cert-v01@openssh.com,rsa-sha2-512-cert-v01@openssh.com,rsa-sha2-256-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com,ssh-dss-cert-v01@openssh.com,ssh-ed25519,ecdsa-sha2-nistp521,ecdsa-sha2-nistp384,ecdsa-sha2-nistp256,rsa-sha2-512,rsa-sha2-256,ssh-rsa,ssh-dss>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
v01@openssh.com,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:Ae2CCQzd33Dczv8gPiRiYEWJ7xwBVOU+719JTJ/5fjQ C:\\Users\\foobar\\.ssh\\foobar\\open_ssh-agent
debug1: Server accepts key: pkalg ssh-rsa blen 279
warning: agent returned different signature type ssh-rsa (expected rsa-sha2-512)
debug1: Authentication succeeded (publickey).
Authenticated to github.com (foobar).
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 vivere! You've successfully authenticated,but GitHub does not provide shell access.
debug1: channel 0: free: client-session,nchannels 1
Transferred: sent 2560,received 2468 bytes,in 0.2 seconds
Bytes per second: sent 10852.5,received 10462.5
debug1: Exit status 1

解决方法

如果 ssh -Tv git@github.com 有效,请检查您是否可以通过以下方式联系远程仓库 SSH URL:

git ls-remote git@github.com:<me>/<myRepo>

然后将该 URL 与在本地存储库 (git remote -v) 中注册的 URL 进行比较
如果相同,请检查 git config -l 的输出:查找任何包含 insteadOf 的指令,以防 URL 被其他内容更改。

OP Vivere 中的 the comments 报告:

  • 必须将密钥命名为 id_rsa 并将其准确保存在 ~/.ssh 中,紧跟 this gist;
  • 使用错误的 ssh-add.exe(来自 OpenSSH 的那个)

基本上:

  • 不要使用 Powershell
  • 使用 PATH 不引用 C:\Windows\System32\OpenSSH\ 的 CMD 会话

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。