我尝试使用设置 git 并将其用于 github,然后当我按照帮助文档进行操作时,但是当我到达设置 ssh 密钥部分的第 5 步时:测试所有内容,当我使用此命令时:ssh -T git@github.com出现错误:
ssh:连接到主机 github.com 端口 22:没有到主机的路由
然后我使用了这个命令:
ssh -vT git@github.com
Run Code Online (Sandbox Code Playgroud)
这是我得到的:
OpenSSH_5.8p1 Debian-7ubuntu1, OpenSSL 1.0.0e 6 Sep 2011
debug1: Reading configuration data /home/jacos/.ssh/config
debug1: Applying options for github.com
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to github.com [207.97.227.239] port 22.
debug1: connect to address 207.97.227.239 port 22: No route to host
ssh: connect to host github.com port 22: No route to host
Run Code Online (Sandbox Code Playgroud)
我用谷歌搜索了一段时间,发现我必须检查 iptables 是否阻止了端口。结果如下:
~$ sudo /sbin/iptables -L -n
[sudo] password for jacos:
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT udp -- 0.0.0.0/0 0.0.0.0/0 udp dpt:67
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:67
ACCEPT udp -- 0.0.0.0/0 0.0.0.0/0 udp dpt:53
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:53
Chain FORWARD (policy ACCEPT)
target prot opt source destination
ACCEPT all -- 0.0.0.0/0 10.42.43.0/24 state RELATED,ESTABLISHED
ACCEPT all -- 10.42.43.0/24 0.0.0.0/0
ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-port-unreachable
REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-port-unreachable
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Run Code Online (Sandbox Code Playgroud)
我尝试了 Gilles 建议的命令:
tcptraceroute github.com 22
Run Code Online (Sandbox Code Playgroud)
这是我得到的:
Selected device eth0, address 222.20.58.XX(sorry...I masked part of my ip), port 33281 for outgoing packets
Tracing the path to github.com (207.97.227.239) on TCP port 22 (ssh), 30 hops max
1 222.20.58.254 0.891 ms 0.850 ms 0.693 ms
2 zxq-xs-h3c7510e.hust.edu.cn (115.156.255.137) 1.253 ms 1.569 ms 2.837 ms
3 zxq-xs-rjs8606.hust.edu.cn (115.156.255.130) 0.729 ms 0.678 ms 0.629 ms
4 115.156.255.174 0.794 ms 6.279 ms 16.569 ms
5 * * *
6 * * *
7 * * *
8 * * *
9 * * *
10 * * *
11 * * *
12 * * *
13 * * *
14 * * *
15 * * *
16 * * *
17 * * *
18 * * *
19 * * *
20 * * *
21 * * *
22 * * *
23 * * *
24 * * *
25 * * *
26 * * *
27 * * *
28 * * *
29 * * *
30 * * *
Destination not reached
Run Code Online (Sandbox Code Playgroud)
好像路线停在115.156.255.174,不知道在哪。
我无法弄清楚这意味着什么。它会阻止端口 22 吗?
顺便说一句,我可以访问互联网并访问github.com。我正在使用 Ubuntu 11.10。
有人能帮忙吗?谢谢!
你的INPUT链条接受一切。您还没有展示您的OUTPUT链条,但我假设它也接受所有内容。这意味着您和 Github 之间的连接被阻止。您学校的防火墙可能会阻止到端口 22 的传出连接。
您可以通过安装tcptraceroute更好地了解数据包在何处被拦截 并运行
tcptraceroute github.com 22。
请学校的管理员打开端口 22,或者至少(如果他们不愿意)将端口 22 打开github.com。您对网络的使用是一种严肃的使用,应该允许学生这样做。
如果管理员不让步,并且您使用代理连接到网络,您也许能够让代理来中继流量(它可能会也可能不会工作,具体取决于代理的配置方式)。请参阅是否可以通过端口 80 进行 SSH?
顺便说一句,您的INPUT链允许所有传入流量,因为您只有ACCEPT规则和ACCEPT策略。典型的规则集将阻止未经审查的端口上的传入 UDP 流量,并阻止未经审查的端口上的传入 TCP 连接:
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A INPUT -p udp --dport 53 -j ACCEPT
iptables -A INPUT -p udp --dport 123 -j ACCEPT
iptables -P INPUT DROP
Run Code Online (Sandbox Code Playgroud)