(其中192.168.10.88是你要允许登陆ssh的ip,或者是一个网段192.168.10.0/24)
sshd:192.168.10.88:allow
在/etc/hosts.deny输入(表示除了上面允许的,其他的ip都拒绝登陆ssh)
sshd:ALL
***************************************************************************
比如说你只允许1.1.1.1这个IP进入,其它都禁止:
方法1、iptables。
iptables -A INPUT -s 1.1.1.1 --destination-port 22 -j ACCEPT
iptables -A INPUT --destination 22 -j DROP
改正:
iptables -A INPUT -p tcp -s 1.1.1.1 --destination-port 22 -j ACCEPT
iptables -A INPUT -p tcp --destination-port 22 -j DROP
方法2:
vi /etc/ssh/sshd_config
添加一行:
allowusers xxx@1.1.1.1 或AllowUsers sysman@192.168.125.*
注:xxx为你用来登入服务器的用户名。
***************************************************************************
方法一:
在/etc/hosts.allow中添加允许ssh登陆的ip或者网段
sshd:192.168.1.2:allow 或者
sshd:192.168.1.0/24:allow
在/etc/hosts.deny添加不允许ssh登陆的IP
sshd:ALL #ALL表示除了上面允许的,其他的ip 都拒绝登陆ssh
方法二:
使用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
方法三:
用 iptables 也行:
iptables -I INPUT -p tcp --dport 22 -j DROP
iptables -I INPUT -p tcp --dport 22 -s 1.2.3.4 -j ACCEPT
2,禁止某个用户通过ssh登录
在/etc/ssh/sshd_conf添加
AllowUsers 用户名
或者
AllowGroups 组名
或者
DenyUsers 用户名
3,设定登录黑名单
vi /etc/pam.d/sshd
增加
auth required /lib/security/pam_listfile.so item=user sense=deny file=/etc/sshd_user_deny_list onerr=succeed
所有/etc/sshd_user_deny_list里面的用户被拒绝ssh登录
下面简单实现Linux 下限制SSH登录IP
/etc/hosts.allow
sshd:192.168.0.100:allow //允许IP 192.168.0.100 登录
sshd:192.168.10.:allow //允许IP 192.168.10. 网段登录
sshd:all:deny //禁止其他的所有IP登录