git clone遇到的[ssh: connect to host github.com port 22]

起因

在学习递归的时候,对汉诺塔小研究了一番,参考网上写了个demo,后面就想同步到github

过程

这台电脑是新电脑,所以需要先本地生成ssh keyssh-keygen -t rsa -C "youremail@example.com"
可参考-远程仓库
第一步:ssh-keygen -t rsa -C "youremail@example.com"
第二步:在用户目录下,找到.ssh文件夹下的id_rsa.pub,打开先复制全部内容;
第三步:登录github,个人帐号setting下的SSH and GPG keys,然后点击右上角的New SSH key。之后把第二步复制的都拷贝到key输入框;
第四步:开始克隆:git clone git@github.com:***/***.git

正常会成功的,可惜报错了!


g1.png

解决

因为公司是代理上网,初步猜测应该是这个问题。

那就googlebaidu寻找解决方式。

根据报错提示,应该是ssh连不通。
网上找到ssh -T git@github.com可参考-Testing your SSH connection
测试过结果如下:


g2.png


所以,接着搜索ssh: connect to host github.com port 22: Connection timed out,发现貌似找到解决方式了。


image.png


可参考-ssh: connect to host github.com port 22: Connection timed out
这个说的就是把协议从ssh方式换成https。先别管本地git config --local -e是否可行,要尽快解决问题。
所以,git clone的时候,换个协议就好了!

git clone https://github.com/***/***.git


image.png

小结

xxx

思考

  1. 为什么ssh协议会存在问题,而https则不会?什么是ssh协议?https协议呢?两者的区别?
  2. git bash下的git clone xxx是怎么发请求的?类似于curl?还是??
  3. xxx
原文地址:https://www.cnblogs.com/simonbaker/p/7191260.html