Git 提交出错ssh: connect to host github.com port 22: Connection timed out fatal: Could not

1、使用SSH协议push本地仓库到远程仓库出现的bug

         Git 提交出错ssh: connect to host github.com port 22: Connection timed out fatal: Could not

在Github文档中查找关于SSH故障的解决办法:https://docs.github.com/en/[email protected]/github/authenticating-to-github/using-ssh-over-the-https-port

Git 提交出错ssh: connect to host github.com port 22: Connection timed out fatal: Could not

文档上说可能是防火墙拒绝允许SSH连接造成的,可以尝试使用通过HTTPS端口建立起SSH连接进行数据传输。SSH服务的端口是22,bug中显示端口22连接超时,HTTPS的端口是443,我们在ssh文件中新建config文件来更改服务端口为443。

2.bugs解决步骤

(1)先确定SSH秘钥配置了吗

我的SSH秘钥已经配置过了,路径是C:\Users\fanzhengxi\.ssh

Git 提交出错ssh: connect to host github.com port 22: Connection timed out fatal: Could not

(2)检查能不能使用443端口覆盖ssh的端口

先切换路径为.ssh路径:cd ~/.ssh

然后输入: ssh -T -p 443 [email protected]

Git 提交出错ssh: connect to host github.com port 22: Connection timed out fatal: Could not

结果显示可用

(3)更改端口为443

可以直接在.ssh文件夹中直接新建一个文本文档config.txt,编辑好后把 .txt后缀去掉,即可得到config文件。我这里使用vim编辑器创建config文件,因为最近学了一些lunix指令,顺便巩固一下,嘻嘻。

Git 提交出错ssh: connect to host github.com port 22: Connection timed out fatal: Could not

i      //输入i进入编辑状态

Git 提交出错ssh: connect to host github.com port 22: Connection timed out fatal: Could not

Esc   //退出编辑

:wq   //回车,保存并退出

Git 提交出错ssh: connect to host github.com port 22: Connection timed out fatal: Could not

cat config //查看config中的内容,看到我们新增的内容已经写好了

Git 提交出错ssh: connect to host github.com port 22: Connection timed out fatal: Could not

查看ssh文件夹,里面也新增了config,并自动生成了known_hosts文件。

(4)检测一下能不能用

输入:ssh -T [email protected]

Git 提交出错ssh: connect to host github.com port 22: Connection timed out fatal: Could not

出现上面的提示说明我们已经可以使用ssh协议push本地仓库了,那就试试吧

第一次push

Git 提交出错ssh: connect to host github.com port 22: Connection timed out fatal: Could not

因为美国黑人弗洛伊德问题,认为master是黑人歧视运动的敏感词汇,现在github上的主分支用main取代了master。

以后有修改要push,直接:git push 就可以了

Git 提交出错ssh: connect to host github.com port 22: Connection timed out fatal: Could not

使用SSH服务来push仓库的好处就是不需要每次push都输github的账号密码,比较方便,使用HTTPS协议来push到远端每次都需要输入账号,密码,有点麻烦。