linux拒絕某IP或某用戶登陸

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登錄
摘自linux/unix技術交流羣裏面的mike
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章