1,只允許某個IP登錄,拒絕其他所有IP
在 /etc/hosts.allow 寫:
sshd: 1.2.3.4
在 /etc/hosts.deny 寫:
sshd: ALL
在 /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
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