【git】解决git报错:ssh:connect to host github.com port 22: Connection timed out 亲测有效

如题,git使用中突然报错

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

通过查阅各种资料,得知原因可能是由于电脑的防火墙或者其他网络原因导致ssh连接方式 端口22被封锁。

解决方法

一:抛弃ssh连接方式,使用http连接。

git config --local -e
将配置文件的url = git@github.com:username/repo.git一行改为:url = https://github.com/username/repo.git

方法二:如果22号端口不行,那就换一个端口

进入.ssh文件夹

在这里插入图片描述
创建一个config文件

将下面的内容复制进去

Host github.com
User git
Hostname ssh.github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
Port 443
 
Host gitlab.com
Hostname altssh.gitlab.com
User git
Port 443
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa

保存退出

检查是否成功

ssh -T git@github.com

在这里插入图片描述

这里要根据它的提示操作,有个地方要输入yes

此时大功告成啦

  • 20
    点赞
  • 31
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
问题描述中提到了在使用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配置文件,以防出现意外情况。希望对您有所帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

fruge365

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值