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

昨天在使用VsCode向GitHub上传代码时,出现错误:(此前已经使用SSH的方式连接了GitHub仓库)

ssh: connect to host github.com port 22: Connection timed out
Please make sure you have the correct access rights
and the repository exists.

首先输入以下命令检查SSH是否能够连接成功(ssh后面有空格)

ssh -T git@github.com

发现报错:

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

端口连接超时。

查阅资料后,找到解决办法:

解决方案(亲测有效)
在C盘——用户——你的主机名文件夹中找到.ssh文件夹;(此前配置SSH时会生成该文件夹)
在.ssh文件夹中新建文件 config,不带后缀(可以新建文本文档,去掉.txt后缀)
使用notepad++(或其他方式)打开config文件,输入以下内容,保存后即可

Host github.com
User YourEmail(你的邮箱)
Hostname ssh.github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
Port 443

再次执行

ssh -T git@github.com

会出现以下提示,输入yes回车即可

The authenticity of host '[ssh.github.com]:443 ([192.30.255.123]:443)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[ssh.github.com]:443,[192.30.255.123]:443' (RSA) to the list of known hosts.

再次执行ssh -T git@github.com,发现验证通过

Hi Clare! You've successfully authenticated, but GitHub does not provide shell access.

完成以上步骤后,再次上传代码到GitHub就不会报错了

作者:Clare0326
链接:https://www.jianshu.com/p/e786a8f7f022
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

  • 11
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这个错误通常是由于连接到GitHubSSH端口(端口22)被拒绝或超时引起的。有几种可能的解决方法: 1. 参考中的解决方案,可以尝试在SSH配置文件中更改GitHub的主机名为ssh.github.com,并将端口设置为443。这样可以使用git pull命令来拉取代码。 2. 参考中的解决方法,可以尝试使用HTTP连接而不是SSH连接。通过修改.git/config文件中的URL,将其改为使用https://github.com/username/repo.git。 3. 参考中的解决方案,可以尝试在SSH配置文件中添加一些内容,包括将GitHub的主机名设置为ssh.github.com,并将端口设置为443。 请注意,端口22被封锁或超时可能是因为网络配置或防火墙设置。如果上述解决方法均无效,建议与网络管理员或GitHub支持团队联系,以获得更多帮助。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [ssh: connect to host github.com port 22: Connection refused fatal: Could not read from remote reposi...](https://blog.csdn.net/weixin_41697143/article/details/129012461)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [解决git报错:ssh:connect to host github.com port 22: Connection timed out](https://blog.csdn.net/yjxkq99/article/details/128927038)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值