解决 Git:ssh: connect to host github.com port 22: Connection timed out 问题的三种方案

这篇具有很好参考价值的文章主要介绍了解决 Git:ssh: connect to host github.com port 22: Connection timed out 问题的三种方案。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

1、问题描述:

其一、整体提示为:

ssh: connect to host github.com port 22: Connection timed out
fatal: Could not read from remote repository.

中文为:

ssh:连接到主机 github.com 端口 22:连接超时
fatal:无法从远程存储库读取

其二、问题描述为:

A、正常的将代码提交到 git 仓库的过程:

step1、找到要提交 git 的代码的地址:
xxxxxxxx@ubuntu:~/work/frs_stp/frs$

step2、查看当前分支的命令:git branch
// 注意此时的分支就是:dev-xxxxxxxx

即:xxxxxxxx@ubuntu:~/work/frs_stp/frs$ git branch

解决 Git:ssh: connect to host github.com port 22: Connection timed out 问题的三种方案,# 前端所遇问题栏,git,ssh,github,经验分享,port 22,前端,虚拟机

step3、查看 git 的提交记录(如:查看四行)的命令:git log --oneline -4

即:xxxxxxxx@ubuntu:~/work/frs_stp/frs$ git log --oneline -4

解决 Git:ssh: connect to host github.com port 22: Connection timed out 问题的三种方案,# 前端所遇问题栏,git,ssh,github,经验分享,port 22,前端,虚拟机

step4、准备提交的状态信息的命令:git status .

即:xxxxxxxx@ubuntu:~/work/frs_stp/frs$ git status .

解决 Git:ssh: connect to host github.com port 22: Connection timed out 问题的三种方案,# 前端所遇问题栏,git,ssh,github,经验分享,port 22,前端,虚拟机

step5、去掉不用提交的页面操作的命令:git checkout
注意:上面的就是准备提交的更改的东西(注意:要只提交 web 的内容),下面的就是准备提交的新的页面;
即(注意有空格):xxxxxxxx@ubuntu:~/work/frs_stp/frs$ git checkout web/server/prog/handlers/* web/server/prog/url_handlers.in web/server/prog/web_common.h

解决 Git:ssh: connect to host github.com port 22: Connection timed out 问题的三种方案,# 前端所遇问题栏,git,ssh,github,经验分享,port 22,前端,虚拟机

step6、再次查看即将要提交信息的命令:git status .

即:xxxxxxxx@ubuntu:~/work/frs_stp/frs$ git status .

解决 Git:ssh: connect to host github.com port 22: Connection timed out 问题的三种方案,# 前端所遇问题栏,git,ssh,github,经验分享,port 22,前端,虚拟机

step7、 git 添加操作的命令:git add .

即:xxxxxxxx@ubuntu:~/work/frs_stp/frs$ git add .

解决 Git:ssh: connect to host github.com port 22: Connection timed out 问题的三种方案,# 前端所遇问题栏,git,ssh,github,经验分享,port 22,前端,虚拟机

step8、提交操作备注信息的操作:git commit -m "[]" .

即:xxxxxxxx@ubuntu:~/work/frs_stp/frs$ git commit -m "[型号][注释][name][web]" .

解决 Git:ssh: connect to host github.com port 22: Connection timed out 问题的三种方案,# 前端所遇问题栏,git,ssh,github,经验分享,port 22,前端,虚拟机

step9、可能要存在的强推动作命令:
(即:此时就是基于 dev-xxxxxxxx 创建的新的分支 personal/xxx/qos):

即:xxxxxxxx@ubuntu:~/work/frs_stp/frs$ git push -u origin dev-xxxxxxxx:personal/xxx/qos --force

解决 Git:ssh: connect to host github.com port 22: Connection timed out 问题的三种方案,# 前端所遇问题栏,git,ssh,github,经验分享,port 22,前端,虚拟机

B、此时出现的问题是:强推动作命令抛错:
之前这种操作并没有问题,此时却抛错;
目的:想要将代码推上去,完成代码的合入;

其三、报错面显示为:

// 此时是提交的最后一步抛错;

解决 Git:ssh: connect to host github.com port 22: Connection timed out 问题的三种方案,# 前端所遇问题栏,git,ssh,github,经验分享,port 22,前端,虚拟机

2、问题分析:

其一、可能是网络的问题;
其二、可能是连接的 ssh 出了问题;
其三、默认推上去的端口 22 被占用;

3、问题解决:

其一、网络问题的排除:
若页面能访问 git 库,一般就说明网络没问题;
若浏览器访问不了页面等网络问题,请看本篇文章:点击跳转

其二、可能是连接的 ssh 出了问题:
在对应代码下输入命令:ssh -T git@github.com
即:jiyinhui@ubuntu:~/work/frs_stp/frs$ ssh -T git@github.com

A、若输出结果如下:说明就是端口 22 被占用的问题;

解决 Git:ssh: connect to host github.com port 22: Connection timed out 问题的三种方案,# 前端所遇问题栏,git,ssh,github,经验分享,port 22,前端,虚拟机

B、若输出结果如下:说明 ssh 的连接没有问题(若不放心就重新 ssh 配置一下);

解决 Git:ssh: connect to host github.com port 22: Connection timed out 问题的三种方案,# 前端所遇问题栏,git,ssh,github,经验分享,port 22,前端,虚拟机

C、若是其它的结果,一般就说明就是 ssh 连接的问题;

其三、默认推上去的端口 22 被占用:

A、输入命令,来查看配置信息 vim ~/.ssh/config

// 此时的信息就是抛错:port 22: Connection timed out 的配置

解决 Git:ssh: connect to host github.com port 22: Connection timed out 问题的三种方案,# 前端所遇问题栏,git,ssh,github,经验分享,port 22,前端,虚拟机
B、修改配置信息为:

解决 Git:ssh: connect to host github.com port 22: Connection timed out 问题的三种方案,# 前端所遇问题栏,git,ssh,github,经验分享,port 22,前端,虚拟机

// 通过 vim ~/.ssh/config 查看的结果为:
// 注意:退出 vim 的命令为 :wq + 回车

解决 Git:ssh: connect to host github.com port 22: Connection timed out 问题的三种方案,# 前端所遇问题栏,git,ssh,github,经验分享,port 22,前端,虚拟机

代码为:

Host github.com
	port 443
	HostName ssh.github.com
	IdentityFile ~/.ssh/xxxxxxxxxxxxxxxxxx

C、此时继续推则能成功推上 git 去:

命令为:xxxxxxxx@ubuntu:~/work/frs_stp/frs$ git push -u origin dev-xxxxxxxx:personal/xxx/qos --force

解决 Git:ssh: connect to host github.com port 22: Connection timed out 问题的三种方案,# 前端所遇问题栏,git,ssh,github,经验分享,port 22,前端,虚拟机

// 然后再执行 ssh -T git@github.com 命令的结果展示为:

解决 Git:ssh: connect to host github.com port 22: Connection timed out 问题的三种方案,# 前端所遇问题栏,git,ssh,github,经验分享,port 22,前端,虚拟机

D、可能存在的问题:

step1、抛 # 的错误:

解决 Git:ssh: connect to host github.com port 22: Connection timed out 问题的三种方案,# 前端所遇问题栏,git,ssh,github,经验分享,port 22,前端,虚拟机

代码为:
// 此时的错误,应该是带了注释 #,而导致的问题抛错(即:去掉该注释, 应该就能解决该问题);

# Default github user self
Host github.com
	port 443 # 默认是22端口
	HostName ssh.github.com
	IdentityFile ~/.ssh/id_rsa

step2、抛错: fatal: Could not read from remote repository.

要检查下,此时配置里的 IdentityFile ~/.ssh/xxxxxxxxxxxxxxxxxx,后面跟的是不是想要的仓库地址;

step3、如何查看 vim ~/.ssh/config 命令中的 config 配置文件:

// 此时说明:.ssh 文件与 work 文件同一等级,查看并修改即可(即:可以通过 Notepad ++ 工具);

解决 Git:ssh: connect to host github.com port 22: Connection timed out 问题的三种方案,# 前端所遇问题栏,git,ssh,github,经验分享,port 22,前端,虚拟机

4、小结:

其一、哪里有不对或不合适的地方,还请大佬们多多指点和交流!
其二、若有转发或引用本文章内容,请注明本博客地址(直接点击下面 url 跳转) https://blog.csdn.net/weixin_43405300,创作不易,且行且珍惜!
其三、有兴趣的话,可以多多关注这个专栏(Vue(Vue2+Vue3)面试必备专栏)(直接点击下面 url 跳转):https://blog.csdn.net/weixin_43405300/category_11525646.html?spm=1001.2014.3001.5482文章来源地址https://www.toymoban.com/news/detail-822562.html

到了这里,关于解决 Git:ssh: connect to host github.com port 22: Connection timed out 问题的三种方案的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 【Git】ssh: connect to host github.com port 22: Connection refused

    错误原因:22端口被拒绝访问 在~/.ssh/config文件(有就直接编辑,没有就创建)里添加以下内容,这样ssh连接GitHub的时候就会使用443端口。 修改完,使用`ssh -T git@github.com`查看是否连接成功

    2024年02月04日
    浏览(32)
  • 【Git 教程系列第 27 篇】ssh: connect to host github.com port 22: Connection refused 的解决方案

    这是【Git 教程系列第 27 篇】,如果觉得有用的话,欢迎关注专栏。 一:问题描述 自己的一个 git 项目,昨天在公司正常 push 的时候,提示文字信息如下 提示截图信息如下 有人说是因为开了代理的原因,不过之前我开着代理提交是没有问题的,但还是试了一试,可惜并没有

    2024年02月08日
    浏览(35)
  • 解决 Git:ssh: connect to host github.com port 22: Connection timed out 问题的三种方案

    其一、整体提示为: ssh: connect to host github.com port 22: Connection timed out fatal: Could not read from remote repository. 中文为: ssh:连接到主机 github.com 端口 22:连接超时 fatal:无法从远程存储库读取 其二、问题描述为: A、正常的将代码提交到 git 仓库的过程: step1、找到要提交 git 的代

    2024年01月25日
    浏览(43)
  • 解决ssh: connect to host github.com port 22: Connection refused

    ssh: connect to host github.com port 22: Connection refused 是连接github.com的端口号22拒绝连接。 可以使用github的443端口。 解决方案 在 ~/.ssh/config 中添加如下字段: 测试是否链接成功 如果出现如下字段则验证成功 The authenticity of host ‘[ssh.github.com]:443 ([20.205.243.160]:443)’ can’t be establishe

    2024年01月22日
    浏览(34)
  • 如何解决:ssh: connect to host github.com port 22: Connection refused

    问题: 进行github操作时出现了下面的错误,如何解决   排查思路: ssh: connect to host github.com port 22: Connection refused  这个错误提示的是连接 github.com 的22端口被拒绝了。可以简单理解为此门不通,既然这个端口号走不通,那换一个端口号试试看。 解决方法一: 网上大多的解决

    2024年02月14日
    浏览(40)
  • 解决 ssh: connect to host github.com port 22: Connection timed out

    今天使用git克隆github上的代码时,一直报错 原以为是公钥过期了,就尝试修改配置公钥,但是尝试了几次都不行,最终在博客上找到了解决方案,在次记录一下,以备不时之需 解决ssh-connect-to-host-github-com-port-22-connection-timed-out_ssh connection time out-CSDN博客 找到.ssh文件夹,创建

    2024年01月24日
    浏览(43)
  • git报错处理:ssh:connect to host github.com port 22: Connection timed out

    git 在上传、下载 文件的时候,报错。 报错信息: ssh:connect to host github.com port 22: Connection timed out 提示这个域名github.com port 的22 端口,链接超时。 我直接访问github.com 这个域名是可以访问的,ping 也是可以ping通的。 使用telnet 链接github.com 的22 端口,报超时错误。 所以,问题

    2024年02月11日
    浏览(38)
  • Git推送到Guthub错误:ssh: connect to host github.com port 22: Connection refused

    可能是中国内地网络环境的原因,Git通过ssh推送到自己的存储库发生以下错误。大概是github.com的22端口被屏蔽了? 通过HTTPS也不行,以下错误提示大意是 2021-08-13 密码认证被移除了。官方中文文档 文档里似乎没说密码认证被移除这回事 官方文档: 在 HTTPS 端口使用 SSH 链接格

    2024年01月23日
    浏览(74)
  • Windows下解决ssh: connect to host github.com port 22: Connection refused

    今日在学习git操作的时候,往远程库github库push代码时报错: 查阅网上资料,发现了这几种做法: 方法一 也是网上大多数文章的做法,在C:UsersUsername.ssh目录下新建一个config文件,文件内容: 可不知为何我还是报错了。。。 方法二 根据英文可以看出,ssh端口号被拒绝了,

    2023年04月08日
    浏览(117)
  • github 推送报错 ssh: connect to host github.com port 22: Connection timed out 解决

    🚀 作者主页: 有来技术 🔥 开源项目: youlai-mall 🍃 vue3-element-admin 🍃 youlai-boot 🌺 仓库主页: Gitee 💫 Github 💫 GitCode 💖 欢迎点赞 👍 收藏 ⭐留言 📝 如有错误敬请纠正! git push 推送 github 报错如下: 找到 .ssh 文件夹新增 config 配置文件 添加以下配置即可 使用 ssh -T g

    2024年01月25日
    浏览(45)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包