Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux綜合 >> Linux資訊 >> 更多Linux

securing your SSH:登入來源與使用者雙重限制

預設情況下,sshd 不受 xinetd 管轄,但可搭配 tcpd 使用。若想限制登入來源,有幾種做法可以搭配。

用 hosts.allow 限制來源

在 hosts.allow 中設定,只允許特定網段,其餘拒絕:

sshd: 192.168.0.
sshd: ALL: deny

用 iptables 限制來源

當然,防火牆也能勝任:

iptables -I INPUT -p tcp --dport 22 -j DROP
iptables -I INPUT -p tcp --dport 22 -s 192.168.0.0/32 -j ACCEPT

提醒你,這裡用的是 -I(插入到鏈的最前面),而且順序不能顛倒,否則規則不會如預期生效。

限制哪些使用者能登入

若還想進一步限定可用的帳號,可以查 man sshd_config 裡的 AllowGroups 與 AllowUsers 設定。另一條路是動用 PAM:

1)修改 /etc/pam.d/sshd:

auth required pam_listfile.so item=user sense=allow file=/etc/sshusers onerr=fail

2)把允許的帳號寫進 /etc/sshusers,例如:

echo "root" >> /etc/sshusers

如此一來,SSH 的登入便同時受到來源位址與帳號雙重把關,安全性自然更上一層。

Copyright © Linux教程網 All Rights Reserved