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

$ git push origin master
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.

提交代码时一直报错,我看别人给的解决方案也在 ~/.ssh下写了config文件
内容:
Host github.com
User 账户名
Hostname ssh.github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
Port 443

还是报错:
$ git push origin master
ssh: connect to host ssh.github.com port 443: Connection timed out
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

【以下回答由 GPT 生成】

这个问题通常是由于网络连接问题导致的。以下是一些可能的解决方案:

  1. 检查网络连接:首先确保你的网络连接正常,可以尝试打开其他网站或应用程序以确认。如果你使用的是公司网络,可能需要联系网络管理员来解决。

  2. 使用SSH代理:有时候某些网络环境下无法直接连接GitHub的SSH服务器。你可以尝试使用SSH代理,将网络流量转发到能够连接GitHub的服务器上。这里有一个示例脚本使用代理连接GitHub:

#!/bin/bash

# 设置代理
export http_proxy="http://your.proxy.server:port"
export https_proxy="http://your.proxy.server:port"

# 连接GitHub
git push origin master

# 清除代理设置
unset http_proxy
unset https_proxy

将上述脚本保存为一个可执行文件,运行它可能会解决连接超时的问题。

  1. 更改SSH端口:GitHub默认使用SSH的22端口,但有时候该端口可能被网络限制或防火墙封锁。你可以尝试更改SSH连接的端口为443,这是通常用于HTTPS的端口。修改SSH配置文件 ~/.ssh/config,添加以下内容:
Host github.com
User 你的账户名
Hostname ssh.github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
Port 443

确保你将 你的账户名~/.ssh/id_rsa 分别替换为你的GitHub用户名和SSH密钥路径。

  1. 检查SSH密钥:确保你生成的SSH密钥已经添加到你的GitHub账户。你可以使用以下命令检查:
cat ~/.ssh/id_rsa.pub

如果输出为空或显示错误,请尝试重新生成和添加SSH密钥。

如果以上解决方案都无效,你可能需要考虑联系GitHub支持团队或寻求更进一步的帮助。



【相关推荐】



如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^