方法一:服务器
在/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为你用来登入服务器的用户名。方法