ssh限制ip远程登录

在ssh远程登录linux中,限制其他非法的ip登录系统的几种实现方法。

方法一、
在/etc/hosts.allow中添加允许ssh登录的ip地址和网段
sshd:192.168.1.2:allow 允许192.168.1.2登录
sshd:192.168.1.0/24:allow 允许192.168.1.0~192.168.1.24登录

在/etc/hosts.deny中添加不允许ssh登录的ip
sshd:ALL 出了hosts.allow中允许的,其他都不允许登录

方法二、
使用iptables
iptables -A INPUT -p tcp -s 192.168.1.2 –destination-port 22 -j ACCEPT
iptables -A INPUT -p tcp –destination-port 22 -j DROP

方法三、
修改sshd_config文件
vi /etc/sshd/sshd_config
添加一行
allowusers root@192.168.1.2

文章目录