$ 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 生成】
这个问题通常是由于网络连接问题导致的。以下是一些可能的解决方案:
检查网络连接:首先确保你的网络连接正常,可以尝试打开其他网站或应用程序以确认。如果你使用的是公司网络,可能需要联系网络管理员来解决。
使用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
将上述脚本保存为一个可执行文件,运行它可能会解决连接超时的问题。
~/.ssh/config
,添加以下内容:Host github.com
User 你的账户名
Hostname ssh.github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
Port 443
确保你将 你的账户名
和 ~/.ssh/id_rsa
分别替换为你的GitHub用户名和SSH密钥路径。
cat ~/.ssh/id_rsa.pub
如果输出为空或显示错误,请尝试重新生成和添加SSH密钥。
如果以上解决方案都无效,你可能需要考虑联系GitHub支持团队或寻求更进一步的帮助。
【相关推荐】