记录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.

Please make sure you have the correct access rights

and the repository exists.

这个报错挺奇怪的,我已经正常提交git到GitHub有一段时间了,一直都很正常

起因是前天git push的时候报这个错,百度了一圈,也没解决

今天重新尝试解决,好在解决了,是SSH端口22被阻止或网络配置问题导致的

解决步骤如下:

1、在命令行中执行以下命令,验证网络连接与端口状态

bash 复制代码
 ssh -T git@github.com

2、验证后提示如下,很可能是网络环境对端口22有严格限制

bash 复制代码
ssh: connect to host github.com port 22: Connection timed out

3、更换端口,端口443强制连接方案,依次执行以下命令

bash 复制代码
touch ~/.ssh/config
 vi ~/.ssh/config

4、执行完 vi ~/.ssh/config之后,会出现一个编辑的状态,按i进入编辑模式,将以下内容复制进去,然后按Esc+:wq保存并退出

bash 复制代码
Host github.com
  Hostname ssh.github.com
  Port 443
  User git
  IdentityFile ~/.ssh/id_ed25519 

5、继续分别执行以下命令

bash 复制代码
chmod 700 ~/.ssh
chmod 600 ~/.ssh/config
chmod 600 ~/.ssh/id_ed25519
 ssh -T git@github.com

6、当执行完 ssh -T git@github.com之后,会提示

bash 复制代码
The authenticity of host '[ssh.github.com]:443 ([xx.xx.xxx.xxx]:443)' can't be established.
ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.
This host key is known by the following other names/addresses:
    ~/.ssh/known_hosts:1: github.com
    Are you sure you want to continue connecting (yes/no/[fingerprint])?

7、这是SSH连接的正常安全验证步骤,我们看到的指纹 SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU 与GitHub官方公布的ED25519指纹一致,可安全确认。
官方指纹查询:GitHub Docs - SSH签名密钥

8、在提示后 输入小写"yes"(必须完整输入,不能只输"y")

bash 复制代码
Warning: Permanently added '[ssh.github.com]:443' (ED25519) to the list of known hosts.
Hi 你的用户名! You've successfully authenticated, but GitHub does not provide shell access.

这条消息表明您的SSH连接已成功建立

Permanently added '[ssh.github.com]:443' ...:主机密钥已成功保存

Hi 你的用户名! You've successfully authenticated:SSH密钥认证通过

GitHub does not provide shell access:这是正常现象(GitHub仅允许Git操作,不提供登录shell)

总结:

现在可以正常执行Git命令了

相关推荐
研究点啥好呢7 小时前
Github热门项目推荐 | 创建你的像素风格!
c++·python·node.js·github·开源软件
lifewange8 小时前
常用的Git命令有哪些?
git
杨云龙UP8 小时前
从0到1快速学会Linux操作系统(基础),这一篇就够了!
linux·运维·服务器·学习·ubuntu·centos·ssh
无限进步_8 小时前
【C++】电话号码的字母组合:从有限处理到通用解法
开发语言·c++·ide·windows·git·github·visual studio
MicrosoftReactor9 小时前
技术速递|使用 Copilot SDK 构建 AI 驱动的 GitHub Issue 分类系统
人工智能·github·copilot
AI成长日志9 小时前
【GitHub开源项目专栏】AI推理优化框架深度解析(上):vLLM架构设计与核心实现
人工智能·开源·github
CV-deeplearning9 小时前
【开源】字节跳动开源 DeerFlow 2.0:一站式 SuperAgent 开发框架,GitHub 星标 5.9 万!
开源·github·deerflow·deerflow 2.0·superagent
C++ 老炮儿的技术栈9 小时前
GCC编译时无法向/tmp 目录写入临时汇编文件,因为设备空间不足,解决
linux·运维·开发语言·汇编·c++·git·qt
英俊潇洒美少年9 小时前
Git 常用命令速查表(前端开发专属版)
git
Freak嵌入式10 小时前
MicroPython LVGL基础知识和概念:显示与多屏管理
开发语言·python·github·php·gui·lvgl·micropython