linux拒绝某IP或某用户登陆

来源:互联网 发布:python tcp 长连接 编辑:程序博客网 时间:2024/06/09 18:13
1,只允许某个IP登录,拒绝其他所有IP
在 /etc/hosts.allow 写:
sshd: 1.2.3.4
在 /etc/hosts.deny 写:
sshd: ALL
用 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登录

原创粉丝点击