Github ssh-agent 无法推送
Posted
技术标签:
【中文标题】Github ssh-agent 无法推送【英文标题】:Github ssh-agent cannot push 【发布时间】:2021-05-28 02:52:34 【问题描述】:我想通过 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 代理已启动并正在运行。我通过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,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
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 -v -T git@github.com
。 “-v”选项将导致 ssh 打印调试输出。然后edit你的问题显示你运行的ssh命令和输出。
@Kenster 我运行了它,显然它对我进行了身份验证,但退出代码仍然是 1?我不明白发生了什么
@phd 无法运行,我在 Windows 上,但我已经在 powershell 中运行:'~' | Resolve-Path
,它显示:C:\Users\s
。另外,ps 中的$env:HOMEPATH
显示\Users\s
【参考方案1】:
如果 ssh -Tv git@github.com 确实有效,请检查您是否可以通过以下方式联系远程 repo SSH URL:
git ls-remote git@github.com:<me>/<myRepo>
然后将该 URL 与在本地存储库中注册的 URL 进行比较 (git remote -v
)
如果相同,请检查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 会话
【讨论】:
我尝试了您推荐的方法,但没有出现异常情况。我设法按照以下说明使其以某种方式工作:link。基本上,我唯一不同的是拥有名为id_rsa
的密钥并完全保存在~/.ssh
中。我想拥有多个密钥并将它们放在 ~/.ssh
目录内的不同目录中,因为我想拆分我的密钥,每个密钥都有自己的用途。例如,我想为 Jenkins 准备一个。从我遇到的情况来看,这是不可能的?必须命名为id_rsa
?
我相信这与 Windows OpenSSH 有关。 where ssh-add | C:\Program Files\Git\usr\bin\ssh-add.exe | C:\Windows\System32\OpenSSH\ssh-add.exe
到目前为止,我一直在 Powershell 和 cmd 中工作,我一直在编写 ssh-add 来添加我的自定义命名键,但它没有用。然后我尝试使用 id_rsa 命名,这很有效,但我必须每次都编写密码,即使它在 ssh-add 中也很烦人。显然,在 git bash 中,一切都按预期工作。我还发现了这个帖子:github.com/PowerShell/Win32-OpenSSH/issues/1263,看起来很有希望。
@Vivere 你可以有多个键:你需要一个 ~/.ssh/config 来区分它们。例如,请参阅***.com/a/66269477/6309。
@Vivere 我已将您的评论包含在答案中,但我的看法是:不要使用 Powershell,使用 PATH 未引用 C:\Windows\System32\OpenSSH
的 CMD
我必须做两件事。一,创建一些脚本来启动代理并添加密钥,二,转移到 Linux。在 Windows 上做任何事情都太难了,这让我发疯了以上是关于Github ssh-agent 无法推送的主要内容,如果未能解决你的问题,请参考以下文章