SSH端口22被防火墙block
起初按照Generating SSH Keys配置我的Ubuntu主机到GitHub间的SSH,但是在测试连接
$ ssh -vT git@github.com
时,出错:
OpenSSH_5.9p1 Debian-5ubuntu1.4, OpenSSL 1.0.1 14 Mar 2012
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to github.com [192.30.252.130] port 22.
debug1: connect to address 192.30.252.130 port 22: Connection timed out
ssh: connect to host github.com port 22: Connection timed out
解决方法一:使用SmartHTTP
将SSH式的URL换成HTTPS式的URL即可。
$ git remote set-url origin https://your_username@github.com/your_username/your_repository.git
如果是第一次连接的话,就
$ git remote add origin https://your_username@github.com/your_username/your_repository.git
这时候push
$ git push origin master
输入你在GitHub上的密码就可以了。第一次Push你的代码Repository到GitHub前,需要先在GitHub上新建好你想要上传到的Repository。
GitHub不支持以此URL进行Push,但可用于Clone。 SSH被block的话,自然也不能用SSH URL来Clone。
GIT式,SSH式,HTTPS式的GitHub URL分别形如:
git://github.com/your_username/your_repository.git
git@github.com:your_username/your_repository.git
https://your_username@github.com/your_username/your_repository.git
解决方法二:修改SSH默认端口
用vim打开SSH默认配置文件
sudo vim /etc/ssh/sshd_config
修改这一行
# What ports, IPs and protocols we listen for
Port 22
将22换成49152~65535之间(短暂端口号ephemeral port,客户端使用的端口号,端口号16位)的一个数字。也可以换成1024~49151之间(登记端口号)的一个数字。但不要换成0~1023之间的数字,因为这些端口号是熟知端口号well-known port number。这1024个端口号已被IANA指派给了TCP/IP最重要的一些应用程序,让所有的用户都知道。这一段参考《计算机网络》(第6版)(谢希仁编著)。
现在测试连接之后就会显示:
Warning: Permanently added the RSA host key for IP address '192.30.252.129' to the list of known hosts.
Hi youngsend! You've successfully authenticated, but GitHub does not provide shell access.
SSH连接成功,之后就可以使用SSH URL进行clone和push了。

本文介绍了当SSH端口22被防火墙封锁时的两种应对策略:一是切换到HTTPS方式与GitHub交互;二是更改SSH服务端口并重新测试连接。
3270

被折叠的 条评论
为什么被折叠?



