"ssh -vT git@github.com" 结果出现错误 "kex_exchange_identification: Connection closed by remote host"。

5

我配置SSH密钥的方式是,我生成了一个新的SSH密钥,并将其添加到了我的GitHub账户中,但出现了一些问题。我尝试了很多方法,但无法解决。

ssh -vT git@github.com

输出:

OpenSSH_8.1p1, OpenSSL 1.1.1d  10 Sep 2019
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to github.com [111.40.234.2] port 22.
debug1: Connection established.
debug1: identity file /c/Users/dell/.ssh/id_rsa type 0
debug1: identity file /c/Users/dell/.ssh/id_rsa-cert type -1
debug1: identity file /c/Users/dell/.ssh/id_dsa type -1
debug1: identity file /c/Users/dell/.ssh/id_dsa-cert type -1
debug1: identity file /c/Users/dell/.ssh/id_ecdsa type -1
debug1: identity file /c/Users/dell/.ssh/id_ecdsa-cert type -1
debug1: identity file /c/Users/dell/.ssh/id_ed25519 type -1
debug1: identity file /c/Users/dell/.ssh/id_ed25519-cert type -1
debug1: identity file /c/Users/dell/.ssh/id_xmss type -1
debug1: identity file /c/Users/dell/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.1
kex_exchange_identification: Connection closed by remote host

我能做什么?


1
你似乎正在使用Windows和Cygwin。这些细节可能应该在你的问题中提到。另外,你的ssh客户端是如何配置的?你具体是如何告诉它使用哪个密钥来连接Github的? - tripleee
3个回答

4

我猜您在网络中使用VPN连接,而且该VPN可能已禁用端口22,因此您需要取消VPN使用或将GitHub连接更改为端口443。

编辑~/.ssh/config文件并保存。

Host github.com
    HostName ssh.github.com
    User git
    Port 443

再次测试(以root身份):

ssh -T git@github.com

输出:

The authenticity of host '[ssh.github.com]:443 ([20.205.243.160]:443)' can't be established.
ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '[ssh.github.com]:443' (ED25519) to the list of known hosts.
Hi xxxxxx You've successfully authenticated, but GitHub does not provide shell access.

1
如果您只有一把密钥,可以尝试使用旧的PEM格式重新生成它,并且不设置密码,以进行测试:
ssh-keygen -t rsa -P "" -m PEM

id_rsa.pub 的内容复制到您的 GitHub 个人资料中,然后重试。

1
我猜想你的~/.ssh/里有太多的密钥。请将ssh指向你所使用的确切密钥。在~/.ssh/config中:
Host github.com
    User git
    HostName github.com
    IdentityFile ~/.ssh/id_rsa # or whatever key you use with Github

然后再次尝试 ssh -Tv git@github.com


1
我只有一个密钥,我尝试了这种方法,但仍然不行。 - aptx1231

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接