惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Martin Fowler
Martin Fowler
D
DataBreaches.Net
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
The GitHub Blog
The GitHub Blog
Blog — PlanetScale
Blog — PlanetScale
Microsoft Security Blog
Microsoft Security Blog
A
About on SuperTechFans
Vercel News
Vercel News
L
LangChain Blog
B
Blog RSS Feed
Y
Y Combinator Blog
IT之家
IT之家
H
Hackread – Cybersecurity News, Data Breaches, AI and More
GbyAI
GbyAI
V
V2EX
博客园 - 三生石上(FineUI控件)
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
阮一峰的网络日志
阮一峰的网络日志
有赞技术团队
有赞技术团队
D
Docker
V
Visual Studio Blog
aimingoo的专栏
aimingoo的专栏
Last Week in AI
Last Week in AI
月光博客
月光博客

轶哥博客

blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog
blog
2023-04-29 · via 轶哥博客

在尝试将代码 push 到 GitHub 时,有时候可能会遇到类似于以下的错误信息:

ssh: connect to host xx.xx.xx.xx port 22: Connection timed out

这个错误表明 SSH 连接在尝试通过 22 端口连接到远程服务器时超时。这可能是由于网络环境、防火墙设置或代理配置等原因导致的。为了解决此问题,我们可以尝试将 SSH 连接切换到 443 端口。

修改 SSH 配置以使用端口 443

要将 SSH 连接切换到 443 端口,我们需要在 ~/.ssh/config 文件中添加以下内容:

Host github.com
  Hostname ssh.github.com
  Port 443

这将使你的 SSH 连接通过 443 端口与 ssh.github.com 进行通信,而不是默认的 22 端口。

如果 ~/.ssh/config 文件不存在,可以手动创建一个。确保在添加配置信息后保存并关闭文件。

测试修改后的 SSH 连接

在修改 SSH 配置后,我们需要测试新的连接设置是否有效。在终端中运行以下命令:

ssh -T git@github.com

如果连接成功,你应该能看到类似于以下的提示信息:

Hi <your-username>! You've successfully authenticated, but GitHub does not provide shell access.

这表明你已经成功通过端口 443 进行 SSH 连接。

验证 push 操作

现在我们已经修改了 SSH 配置并测试了新的连接设置,可以尝试再次将代码 push 到 GitHub。在本地仓库中运行以下命令:

git push origin <branch-name>

<branch-name> 替换为你要推送的分支名称。如果一切顺利,你应该能够成功将代码 push 到 GitHub。

总结: 通过修改 SSH 配置并使用 443 端口进行连接,我们成功解决了 "ssh: connect to host xx.xx.xx.xx port 22: Connection timed out" 错误。如果在将来遇到类似问题,可以尝试使用本文提供的方法进行解决。