git上传代码报错ssh: connect to host github.com port 22: Connection timed out解决办法

当在远程库上设置了SSH 之后还是报错连接超时,问题如下

$ 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是否能够连接成功,输入以下命令

ssh -T git@github.com

稍等片刻如果继续报错,如下:

ssh: connect to host github.com port 22: Connection timed out
则,可以使用一下解决办法


打开存放ssh的目录

cd ~/.ssh 

ls

查看是否存在 id_rsa   id_rsa.pun  known_hosts 三个文件,如果没有移步解决办法:

https://blog.csdn.net/u014344668/article/details/78931031

如果存在,则新建config文件输入下面内容

Host github.com
User YourEmail@163.com
Hostname ssh.github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
Port 443

其中User后面为GitHub的账号名称

创建方法:

vim comfig

然后编辑,最后:wq退出

保存之后再次执行"ssh -T git@github.com"时,会出现如下提示,回车"yes"即可

这里写图片描述

这时验证就可以通过。

这里写图片描述

 

本文总结自:

https://blog.csdn.net/vosang/article/details/50499300  解决问题

https://blog.csdn.net/wiki_su/article/details/50247551  如何创建config

  • 51
    点赞
  • 84
    收藏
    觉得还不错? 一键收藏
  • 21
    评论
问题描述中提到了在使用Ubuntu系统时出现了"ssh: connect to host github.com port 22: Connection timed out"的错误。这个错误表示连接到github.comSSH端口22超时了。为了解决这个问题,可以尝试以下方法: 1. 修改SSH配置文件: - 打开终端并输入以下命令:`sudo vim /etc/ssh/ssh_config` - 找到`#Port 22`这一行(可能是注释状态),将其修改为`Port 443`(如果没有这一行,可以直接添加) - 保存并退出配置文件 - 重新连接到github.com,看是否问题已经解决 2. 使用不同的SSH命令: - 打开终端并输入以下命令:`ssh -T git@ssh.github.com` 或 `ssh -T -p 443 git@github.com` - 如果连接成功并显示"You've successfully authenticated",则说明问题已解决;如果仍然显示"ssh: connect to host github.com port 22: Connection timed out",则继续尝试以下命令 - 输入命令:`ssh -T -p 443 git@ssh.github.com` - 检查是否有异常信息显示 3. 配置新的端口: - 打开终端并输入以下命令:`cd ~/.ssh && vim config` - 在编辑器中添加以下内容并保存退出: ``` Host github.com User git Hostname ssh.github.com PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa Port 443 ``` - 重新连接到github.com,看是否问题已经解决 这些方法应该能帮助您解决Ubuntu系统中的"ssh: connect to host github.com port 22: Connection timed out"错误。记得在尝试这些方法之前先备份您的SSH配置文件,以防出现意外情况。希望对您有所帮助!
评论 21
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值