方法一:服務器
在/etc/hosts.allow中添加容許ssh登錄的ip或者網段
sshd:192.168.1.2:allow 或者ssh
sshd:192.168.1.0/24:allow tcp
在/etc/hosts.deny添加不容許ssh登錄的IP
sshd:ALL #ALL表示除了上面容許的,其餘的ip 都拒絕登錄sship
方法二:io
使用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 table
方法三:配置
修改ssh配置文件iptables
vi /etc/ssh/sshd_config
添加一行:
allowusers xxx@192.168.1.2
注:xxx爲你用來登入服務器的用戶名。方法