Linux服務器安全登錄設置
在日常運維工作中,對加固服務器的安全設置是一個機器重要的環境。比較推薦的做法是:
1)嚴格限制ssh登陸(參考:Linux系統下的ssh使用(依據個人經驗總結)):
修改ssh默認監聽端口
禁用root登陸,單獨設置用於ssh登陸的賬號或組;
禁用密碼登陸,采用證書登陸;
ListenAddress綁定本機內網ip,即只能ssh連接本機的內網ip進行登陸;
2)對登陸的ip做白名單限制(iptables、/etc/hosts.allow、/etc/hosts.deny)
3)可以專門找兩臺機器作為堡壘機,其他機器做白名單後只能通過堡壘機登陸,將機房服務器的登陸進去的口子收緊;
另外,將上面限制ssh的做法用在堡壘機上,並且最好設置登陸後的二次驗證環境(Google-Authenticator身份驗證)
4)嚴格的sudo權限控制(參考:linux系統下的權限知識梳理)
5)使用chattr命令鎖定服務器上重要信息文件,如/etc/passwd、/etc/group、/etc/shadow、/etc/sudoers、/etc/sysconfig/iptables、/var/spool/cron/root等
6)禁ping(echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all)
今天這裏主要說下服務器安全登陸的白名單設置,通過下面兩種方法:
1)iptables對ssh端口做限制;
2)/etc/hosts.allow和/etc/hosts.deny限制;這兩個文件是控制遠程訪問設置的,通過他可以允許或者拒絕某個ip或者ip段的客戶訪問linux的某項服務。
如果當iptables、hosts.allow和hosts.deny三者都設置時或設置出現沖突時,遵循的優先級是hosts.allow > hosts.deny >iptables
下面來看一下幾個限制本地服務器登陸的設置:
1)iptables和hosts.allow設置一致,hosts.deny不設置。如果出現沖突,以hosts.allow設置為主。
[[email protected]
.....
-A INPUT -s 192.168.1.0/24 -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -s 114.165.77.144 -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -s 133.110.186.130 -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
[[email protected]