![连接到主机 xx.xx.xx.xx 端口 22:连接超时](https://linux22.com/image/894841/%E8%BF%9E%E6%8E%A5%E5%88%B0%E4%B8%BB%E6%9C%BA%20xx.xx.xx.xx%20%E7%AB%AF%E5%8F%A3%2022%EF%BC%9A%E8%BF%9E%E6%8E%A5%E8%B6%85%E6%97%B6.png)
我正在尝试 SSH 到我的服务器。当我使用以下命令检查时,SSH 服务处于活动状态
sudo service ssh status
此外,当我执行 netstat -nat | grep 22 时,我得到了
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 xx.xx.xx.xx:22 xx.xx.xx.xx:54197 ESTABLISHED
tcp6 0 0 :::22 :::* LISTEN
我在终端上运行以下命令:
ssh [email protected]
我收到以下错误
ssh: connect to host xx.xx.xx.xx port 22: Connection timed out
我还通过 iptables 限制了对我的服务器的访问。当我输入 iptables -L 时,我得到以下几行:
Chain INPUT (policy DROP)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp dpt:ssh
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT all -- anywhere anywhere
ACCEPT all -- x.x.x.x anywhere
ACCEPT all -- x.x.x.x anywhere
ACCEPT all -- x.x.x.x anywhere
ACCEPT all -- x.x.x.x anywhere
ACCEPT all -- x.x.x.x anywhere
ACCEPT all -- x.x.x.x anywhere
ACCEPT all -- x.x.x.x anywhere
ACCEPT all -- x.x.x.x anywhere
ACCEPT all -- x.x.x.x anywhere
ACCEPT all -- x.x.x.x anywhere
ACCEPT all -- x.x.x.x anywhere
ACCEPT all -- x.x.x.x anywhere
ACCEPT all -- x.x.x.x anywhere
ACCEPT all -- x.x.x.x anywhere
ACCEPT all -- x.x.x.x anywhere
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp dpt:ssh
Chain FORWARD (policy DROP)
target prot opt source destination
Chain OUTPUT (policy DROP)
target prot opt source destination
ACCEPT all -- anywhere x.x.x.x
ACCEPT all -- anywhere x.x.x.x
ACCEPT all -- anywhere x.x.x.x
ACCEPT all -- anywhere x.x.x.x
ACCEPT all -- anywhere x.x.x.x
ACCEPT all -- anywhere x.x.x.x
ACCEPT all -- anywhere x.x.x.x
ACCEPT all -- anywhere x.x.x.x
ACCEPT all -- anywhere x.x.x.x
ACCEPT all -- anywhere x.x.x.x
ACCEPT all -- anywhere x.x.x.x
ACCEPT all -- anywhere x.x.x.x
ACCEPT all -- anywhere x.x.x.x
ACCEPT all -- anywhere x.x.x.x
ACCEPT tcp -- anywhere anywhere tcp spt:ssh
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp spt:ssh
ACCEPT tcp -- anywhere anywhere tcp dpt:ssh
ACCEPT tcp -- anywhere anywhere tcp dpt:ssh
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
我完全不知道该如何解决这个问题。有人能帮我吗?
问候,凯文
答案1
可能是您未将 SSH 配置文件中的“PermitRootLogin”设置为接受使用 root 帐户的连接。在配置文件中(我的是 /etc/ssh/sshd_config),此设置默认为“no”(出于安全原因)。尝试使用具有 SSH 访问权限的其他用户帐户进行连接,或尝试将 PermitRootLogin 更改为“yes”,然后查看会发生什么。