当前位置: 首页 > OpenSource, security > 正文

ssh无法登录的问题

今天遇到朋友问我这样一个问题,托管的服务器ssh不好用了,无法登录。

症状是: ssh 端口可以telnet 通,但是就是无法远程登录上去,用同网段的另外一台服务器可以登录上去,

比较奇怪,于是让我帮忙看看。

我中转登上去看了一下,经历了如下步骤:

  • iptables没有问题,iptables -vnL 看一了下规则,也没有问题,保险起见我把iptables停掉了,
  • 检查ssh服务,看了sshd的配置,重启服务,未果。
  • 查看了系统日志,检测一下是否被人入侵了,/var/log 全面检测,发现没有什么异样。

这就奇怪了,难道要我重装sshd吗?

  • 查看/etc/hosts.allow 和/etc/hosts.deny ,原来问题再这里,

里面有类似这样的设置:

[root@2hei.net ]# more /etc/hosts.allow
#
# hosts.allow   This file describes the names of the hosts which are
#               allowed to use the local INET services, as decided
#               by the ‘/usr/sbin/tcpd’ server.
#
sshd:192.168.1.100:allow
vsftpd:192.168.1.100:allow

[root@2hei.net ]# more /etc/hosts.deny
#
# hosts.deny    This file describes the names of the hosts which are
#               *not* allowed to use the local INET services, as decided
#               by the ‘/usr/sbin/tcpd’ server.
#
# The portmap line is redundant, but it is left to remind you that
# the new secure portmap uses hosts.deny and hosts.allow.  In particular
# you should know that NFS uses portmap!
sshd:ALL:deny
vsftpd:ALL:deny

 

把/etc/hosts.deny的注释掉,或者把/etc/hosts.allow加上允许的IP即可。

总结一下:

iptables和hosts文件共同使用是,注意ip段。

另外hosts并不能禁掉ssh的端口,其他人虽然无法登陆,但是telnet ssh端口却可以发现服务开着,所以iptables还是有必要使用的。

 

本文固定链接: https://www.2hei.net/2008/01/25/ssh_iptables_hosts_allow_deny/ | 2hei.net

该日志由 u2 于2008年01月25日发表在 OpenSource, security 分类下,
原创文章转载请注明: ssh无法登录的问题 | 2hei.net
关键字: , ,

报歉!评论已关闭.