Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

Linux 系統安全防護十大實戰技巧

編輯:Linux 教學

系統安全性對 Linux 使用者至關重要。本文整理了十項實用的安全強化技巧,幫助您建立更堅固的防護體系。

1. 為 LILO 設定開機密碼

編輯 /etc/lilo.conf,新增 password 參數,使 LILO 啟動時要求輸入密碼。設定範例:

boot=/dev/hda
map=/boot/map
install=/boot/boot.b
timeout=60
prompt
default=linux
password=您的密碼
image=/boot/vmlinuz-2.2.14-12
label=linux
initrd=/boot/initrd-2.2.14-12.img
root=/dev/hda6
read-only

注意:LILO 密碼以明文儲存,務必將 lilo.conf 權限設為 600(chmod 600 /etc/lilo.conf),並執行 /sbin/lilo -v 使變更生效。

2. 設定密碼最小長度與最短使用天數

修改 /etc/login.defs:將 PASS_MIN_LEN 設為 8 以上,並設定 PASS_MIN_DAYS 強制定期更換密碼,防止暴力破解。

3. 啟用使用者閒置自動登出

編輯 /etc/profile,在 HISTFILESIZE 之後加入 TMOUT=600,使用者 10 分鐘無操作將自動登出,降低帳號被盜用風險。

4. 保護關鍵系統檔案

對 inetd.conf、services、lilo.conf 等敏感檔案執行:

chmod 600 /etc/inetd.conf
chattr +i /etc/inetd.conf

chattr +i 使檔案不可變更,即使 root 也需先執行 chattr -i 才能修改。

5. 利用 TCP Wrappers 管控遠端存取

編輯 /etc/hosts.deny 拒絕所有連線(ALL: ALL@ALL),再在 /etc/hosts.allow 明確允許特定 IP/主機名存取特定服務(如 ftp: 202.84.17.11 xinhuanet.com)。完成後用 tcpdchk 驗證設定。

6. 限制 Shell 指令歷史記錄大小

修改 /etc/profile 中的 HISTFILESIZE=30 或 HISTSIZE=30,減少敏感指令殘留風險。

7. 登出時自動清除指令歷史

在 /etc/skel/.bash_logout 加入 rm -f $HOME/.bash_history,所有使用者登出時自動刪除歷史記錄。亦可針對單一使用者(如 root)在其家目錄下的 .bash_logout 設定。

8. 移除不必要的 SUID/SGID 程式

掃描系統:find / -type f \( -perm -04000 -o -perm -02000 \) -print | less。對不需提權的程式執行 chmod a-s 程式名稱 移除特殊權限位。

9. 檢查開機訊息

執行 dmesg > bootmessage 將開機訊息導向檔案,便於事後排查啟動異常。

10. 定期維護磁碟空間

善用 df -k 檢視檔系統使用率,du -s /路徑 統計目錄佔用總量,及時清理冗餘檔案,避免磁碟滿載導致服務中斷。

Copyright © Windows教程網 All Rights Reserved