解决ssh:connect to host github.com port 22: Connection timed out与kex_exchange_identification

这篇具有很好参考价值的文章主要介绍了解决ssh:connect to host github.com port 22: Connection timed out与kex_exchange_identification。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

一、问题

无法进行clone项目和其他Git操作。执行检测连接命令 ssh -T git@github,com报错
ssh:connect to host github.com port 22: Connection timed out
即:连接22端口超时
解决ssh:connect to host github.com port 22: Connection timed out与kex_exchange_identification,ssh,github,运维

涉及到的文件
C:\Users\JIACHENGER.ssh\config
C:\Users\JIACHENGER.ssh\github_id_rsa
C:\Users\JIACHENGER.ssh\github_id_rsa.pub

C:\Users\JIACHENGER\.ssh\known_hosts生成SSH连接日志

host文件
C:\Windows\System32\drivers\etc\hosts
IP域名本地映射文件,只要在本机中查到了指定的域名,就不会继续去DNS(域名系统)中继续查找。
Windows设置本地DNS域名解析hosts文件配置

配置SSH公私钥可参考我这篇:GitHub&Gitee&Gitlab&极狐(JihuLab)同时生成并配置和检测不同SSH公私钥详细过程

二、解决问题

2.1 ssh:connect to host github.com port 22: Connection timed out

//详细连接过程,-v表示verbose  
ssh -vT git@github.com
或者
ssh -Tvvv git@github.com

//nslookup是域名解析工具,8.8.8.8是Google的DNS服务器地址
nslookup github.com 8.8.8.8

//使用本机已经设置好的DNS服务器进行域名解析
nslookup github.com

解决ssh:connect to host github.com port 22: Connection timed out与kex_exchange_identification,ssh,github,运维
这里::1IPV6的localhost地址127.0.0.1IPV4的localhost地址。这里基本可以认为是DNS域名解析出了问题,导致GitHub的域名被解析成了本地localhost的ip地址,导致无法连接上GitHub。

2.2 kex_exchange_identification: Connection closed by remote host

此时又出现了一个问题

kex_exchange_identification: Connection closed by remote host
Connection closed by ::1 port 22

解决ssh:connect to host github.com port 22: Connection timed out与kex_exchange_identification,ssh,github,运维

C:\Users\JIACHENGER\.ssh\known_hosts备份,后将known_hosts内容清空,再重新执行检测连接命令 ssh -T git@github,com,这样做偶尔可以连接成功,但过了一会儿还是会报同样的错误
解决ssh:connect to host github.com port 22: Connection timed out与kex_exchange_identification,ssh,github,运维
我同时配置SSH公私钥的除了GitHub以外的其他平台(Gitee&Gitlab&极狐(JihuLab))都可以重新正常连接(过程中需要输入yes确认,表示确认添加主机到可信任列表本机在之前第一次生成SSH公私钥的时候,没有配置访问密码),并且在C:\Users\JIACHENGER\.ssh\known_hosts生成连接日志,如下图:
GitHub&Gitee&Gitlab&极狐(JihuLab)同时生成并配置和检测不同SSH公私钥详细过程
解决ssh:connect to host github.com port 22: Connection timed out与kex_exchange_identification,ssh,github,运维

2.3 排除端口

C:\Users\JIACHENGER\.ssh\config 中,若config中没有指定端口,默认使用22端口,进行SSH连接。
使用443端口(默认情况)config配置如下:
注意:GitHub端口 443 的主机名Hostnamessh.github.com,而不是 github.com

# github
# ssh -T git@github.com
Port 443    
#Port 22 
Host github.com
Hostname ssh.github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/github_id_rsa

使用22端口(默认情况,不配置也是使用22端口)config配置如下:

# github
# ssh -T git@github.com
#Port 443    
Port 22 
Host github.com
Hostname github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/github_id_rsa

仍然还会报同样的错误说明大概率和端口没有关系:
解决ssh:connect to host github.com port 22: Connection timed out与kex_exchange_identification,ssh,github,运维

2.4 在hosts中手动配置GitHub域名映射解决问题

host文件C:\Windows\System32\drivers\etc\hosts手动配置GitHub域名映射,在文件末尾处增加一行 140.82.113.4 github.com。此处的域名github.comC:\Users\JIACHENGER\.ssh\config文件中GitHub配置的Hostname值一致,均为github.com

# github
# ssh -T git@github.com
#Port 443  
#注意:GitHub端口 443 的主机名Hostname为 ssh.github.com,而不是 github.com。  
#Port 22  此处注释,默认也使用22端口
Host github.com
Hostname github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/github_id_rsa

IP域名本地映射文件,只要在本机中查到了指定的域名,就不会继续去DNS(域名系统)中继续查找。
参考:Windows设置本地DNS域名解析hosts文件配置

# Added by Docker Desktop
192.168.1.14 host.docker.internal
192.168.1.14 gateway.docker.internal
# To allow the same kube context to work on the host and the container:
127.0.0.1 kubernetes.docker.internal
# End of section


#2023-9-19 19:08:03 配置
#解决ssh:connect to host github.com port 22: Connection timed out等问题
#在hosts中手动配置GitHub域名映射

140.82.113.4 github.com

C:\Windows\System32\drivers\etc\hosts中手动配置GitHub域名映射使用时,同时不需要在C:\Users\JIACHENGER\.ssh\config 文件中配置端口,默认使用22端口
如下

# github
# ssh -T git@github.com
#Port 443    
#Port 22 
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/github_id_rsa

如果配置了端口,就会报下面的错误:

解决ssh:connect to host github.com port 22: Connection timed out与kex_exchange_identification,ssh,github,运维

在hosts中手动配置GitHub域名映射后检测GitHub连接(config中不配置端口,默认使用22端口),成功连接

$ ssh -T git@github.com
Hi DJCKING! You've successfully authenticated, but GitHub does not provide shell access.

解决ssh:connect to host github.com port 22: Connection timed out与kex_exchange_identification,ssh,github,运维

三、参考

测试 SSH 连接
在 HTTPS 端口使用 SSH
GitHub&Gitee&Gitlab&极狐(JihuLab)同时生成并配置和检测不同SSH公私钥详细过程
Git问题:解决“ssh:connect to host github.com port 22: Connection timed out”
坑:ssh: connect to host github.com port 22: Connection refused
Windows设置本地DNS域名解析hosts文件配置
ssh远程登录报错:kex_exchange_identification: Connection closed by remote host文章来源地址https://www.toymoban.com/news/detail-737854.html

到了这里,关于解决ssh:connect to host github.com port 22: Connection timed out与kex_exchange_identification的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • github 推送报错 ssh: connect to host github.com port 22: Connection timed out 解决

    🚀 作者主页: 有来技术 🔥 开源项目: youlai-mall 🍃 vue3-element-admin 🍃 youlai-boot 🌺 仓库主页: Gitee 💫 Github 💫 GitCode 💖 欢迎点赞 👍 收藏 ⭐留言 📝 如有错误敬请纠正! git push 推送 github 报错如下: 找到 .ssh 文件夹新增 config 配置文件 添加以下配置即可 使用 ssh -T g

    2024年01月25日
    浏览(45)
  • Git问题:解决“ssh:connect to host github.com port 22: Connection timed out”

    操作系统 Windows11 使用Git IDEA 连接方式:SSH 今天上传代码出现如下报错:ssh:connect to host github.com port 22: Connection timed out 再多尝试几次,依然是这样。 最终发现两个解决方案:(二选一) 方法一: 抛弃ssh连接方式,使用http连接。(我试了一下,对于我来说没有用) 操作方法

    2024年02月10日
    浏览(36)
  • 解决git报错:ssh:connect to host github.com port 22: Connection timed out

    如题,git使用中突然报错 ssh:connect to host github.com port 22: Connection timed out 通过查阅各种资料,得知原因可能是由于电脑的防火墙或者其他网络原因导致ssh连接方式 端口22被封锁。 一:抛弃ssh连接方式,使用http连接。 进入.ssh文件夹   创建一个config文件 将下面的内容复制进去

    2024年02月16日
    浏览(35)
  • Git提交 ssh: connect to host github.com port 22: Connection timed out解决方案

    你们好,我是金金金。 之前都是好好的,不知道今天为什么提交代码就这样了 根据英文可以看出,ssh端口号被拒绝了,22号端口不行,那就换一个端口 ssh端口被拒绝 找到.ssh文件,在下面创建一个config文件,然后记事本打开写入以下内容 成功提交 主要是ssh 22端口被拒绝,我

    2024年01月22日
    浏览(49)
  • ssh: connect to host github.com port 22: Connection refused

    最近使用 git 拉取 Github 上的项目时老是出现 Connection refused : 网上的解决办法 解决ssh: connect to host github.com port 22: Connection refused 但是在使用了这个方法后依然无法解决: 然后看见隔壁工位上大哥的搜索栏上赫然也是这个问题,交流一番应该是最近墙比较敏感的问题。 解决方

    2024年02月13日
    浏览(31)
  • 【Git 教程系列第 27 篇】ssh: connect to host github.com port 22: Connection refused 的解决方案

    这是【Git 教程系列第 27 篇】,如果觉得有用的话,欢迎关注专栏。 一:问题描述 自己的一个 git 项目,昨天在公司正常 push 的时候,提示文字信息如下 提示截图信息如下 有人说是因为开了代理的原因,不过之前我开着代理提交是没有问题的,但还是试了一试,可惜并没有

    2024年02月08日
    浏览(35)
  • 解决 Git:ssh: connect to host github.com port 22: Connection timed out 问题的三种方案

    其一、整体提示为: ssh: connect to host github.com port 22: Connection timed out fatal: Could not read from remote repository. 中文为: ssh:连接到主机 github.com 端口 22:连接超时 fatal:无法从远程存储库读取 其二、问题描述为: A、正常的将代码提交到 git 仓库的过程: step1、找到要提交 git 的代

    2024年01月25日
    浏览(43)
  • 【git】解决git报错:ssh:connect to host github.com port 22: Connection timed out 亲测有效

    如题,git使用中突然报错 ssh:connect to host github.com port 22: Connection timed out 通过查阅各种资料,得知原因可能是由于电脑的防火墙或者其他网络原因导致ssh连接方式 端口22被封锁。 创建一个config文件 将下面的内容复制进去 保存退出 检查是否成功 这里要根据它的提示操作,有个

    2024年02月05日
    浏览(47)
  • 【Git】ssh: connect to host github.com port 22: Connection refused

    错误原因:22端口被拒绝访问 在~/.ssh/config文件(有就直接编辑,没有就创建)里添加以下内容,这样ssh连接GitHub的时候就会使用443端口。 修改完,使用`ssh -T git@github.com`查看是否连接成功

    2024年02月04日
    浏览(32)
  • 解决ssh:connect to host github.com port 22: Connection timed out与kex_exchange_identification

    无法进行clone项目和其他Git操作。执行检测连接命令 ssh -T git@github,com 报错 ssh:connect to host github.com port 22: Connection timed out 即:连接22端口超时 涉及到的文件 : C:UsersJIACHENGER.sshconfig C:UsersJIACHENGER.sshgithub_id_rsa C:UsersJIACHENGER.sshgithub_id_rsa.pub C:UsersJIACHENGER.sshknown_hosts 生成

    2024年02月06日
    浏览(44)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包