解决git push提交超时问题ssh: Connection timed out

ssh的连接方式 git push 时报错信息

git push时失败,连接到主机github.com端口22,连接超时

js 复制代码
git push origin main:main
ssh: connect to host github.com port 22: Connection timed out
fatal: Could not read from remote repository.

ps:

git-push原点main:main
ssh:连接到主机github.com端口22:连接超时

致命:无法从远程存储库中读取。

请确保您拥有正确的访问权限并且存储库存在。

百度解决方案

  • 重新生成ssh密钥
  • 修改git用户邮箱设置
  • 删除 known_hosts 中有关 Github相关行

大部分csdn解决方法是说需要重新生成ssh密钥,但我前几天刚提交过代码的,ssh密钥肯定是没问题的!

问题原因

出现这个问题,很可能是你的网络供应商(比如广电网)在出口防火墙上屏蔽了22端口(本地使用vpn等代理服务),这意味着你将无法访问其他主机的22端口。

github提供了一种解决方案,允许你使用443端口进行ssh连接

因为443端口是访问https网站 所必须的,大部分防火墙都会允许通过,但如果使用代理服务器可能产生干扰。

解决方案

方法1

放弃使用 ssh 连接方式,换成 https连接。删除关联的远程库,更换为https的连接方式进行远程库的关联

ssh切换http

arduino 复制代码
git remote set-url origin https://github.com/xxxgit    

http切换ssh

kotlin 复制代码
$ git remote set-url origin git@github.com:xxx.git 

方法2

终端运行如下命令:

css 复制代码
ssh -T -p 443 git@ssh.github.com

win10 找到配置文件 C:\Users\xxx\.ssh\config

添加配置,让你每次ssh连接github都通过443端口,指明ssh连接git@github.comgit@ssh.github.com走443端口

config文件添加如下内容:

sql 复制代码
Host github.com
Hostname ssh.github.com
Port 443
User git

重新执行,检查是否成功

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

成功如下:

此时进行 git push 发现可以成功了。

相关推荐
ISkp3V8b425 分钟前
BMAD方法 v6 与 GitHub Copilot 在应用开发中的协同
github·copilot
CQU_JIAKE33 分钟前
4.4【Q】
java·前端·javascript
小陈工39 分钟前
Python Web开发入门(十二):使用Flask-RESTful构建API——让后端开发更优雅
开发语言·前端·python·安全·oracle·flask·restful
木斯佳39 分钟前
前端八股文面经大全:字节前端一面(2026-04-03)·面经深度解析
前端·面试题·面经
xiaotao1311 小时前
第八章:实战项目案例
前端·vue.js·vite·前端打包
We་ct1 小时前
JS手撕:性能优化、渲染技巧与定时器实现
开发语言·前端·javascript·面试·性能优化·定时器·性能
taWSw5OjU1 小时前
vue对接海康摄像头-H5player
开发语言·前端·javascript
huwuhang1 小时前
跨平台电子书阅读器 | Readest最新版 安卓版+PC版全平台
android·前端·javascript
C澒1 小时前
AI 生码:RAG 检索优化实现可评估、可回溯工程化
前端·ai编程
条tiao条1 小时前
不止语法糖:TypeScript Set 与 Map 深度解析
前端·javascript·typescript