從圖形化管理轉向文字配置檔,是 Linux 管理員必經之路。本文提煉七大關鍵步驟,從帳號管控、網路邊界、加密通訊、服務極小化、郵件防護、入侵偵測到持續滲透測試,構建纵深防禦體系,大幅降低被入侵風險。
/etc/securetty 限制 root 登入終端(僅 tty1、ttyS0)。TMOUT=300 閒置自動登出、HISTFILESIZE=0 禁用歷史紀錄(防洩敏感指令)。PermitRootLogin no)。iptables/nftables 定義 INPUT/OUTPUT/FORWARD 規則鏈。ESTABLISHED,RELATED)。ACCEPT/DROP/REJECT/LOG。INPUT DROP),僅放行必要服務埠(SSH 22、HTTP 80、HTTPS 443 等)。nmap -sS -p- localhost、iptables -L -v -n 計數器確認無漏洞。limit 模組限制連線速率、recent 模組封鎖掃描 IP。sshd_config 關鍵設定:Port 2222 # 非標準埠減少掃描噪音
Protocol 2
PermitRootLogin prohibit-password
PubkeyAuthentication yes
PasswordAuthentication no # 強制金鑰認證
PermitEmptyPasswords no
MaxAuthTries 3
ClientAliveInterval 300
ClientAliveCountMax 2
AllowUsers admin@192.168.1.0/24 # 限制用戶與來源 IP
ssh-keygen -t ed25519、ssh-copy-id、私鑰加密儲存、定期輪換。systemctl list-unit-files --state=enabled / chkconfig --list。systemctl disable --now ftp telnet uucp ntalk rpcbind nfs-server 等。/etc/inetd.conf//etc/xinetd.d/ 註釋舊式服務。bind-address = 127.0.0.1。procmail/sieve 規則自動分類標記垃圾信。freshclam 定時更新病毒碼庫,clamd 守護進程掃描郵件附件。content_filter = smtp-amavis:[127.0.0.1]:10024 → Amavisd-new 串接 SpamAssassin + ClamAV → 回郵件隊列。| 類型 | 代表工具 | 原理 | 優勢 | 劣勢 |
|---|---|---|---|---|
| 主機型 (HIDS) | Tripwire / AIDE | 檔案完整性檢查(雜湊比對) | 精準檢測檔案竄改、Rootkit | 資源消耗大、誤報需人工調校 |
| 網路型 (NIDS) | Snort / Suricata | 規則匹配封包負載、異常流量分析 | 即時封鎖攻擊、覆蓋全網段 | 規則維護複雜、加密流量不可見 |
部署建議:關鍵伺服器裝 HIDS,網路邊界/核心交換器鏡像埠掛 NIDS。告警整合至 SIEM(如 ELK、Wazuh)統一研判。
扮演攻擊者,嘗試突破前六道防線:
john --wordlist=rockyou.txt /etc/shadow、hashcat。nmap -sS -sV -p- target、netstat -tulpn 本地核對。tcpdump -i eth0 -w capture.pcap 分析異常協定。openvas、nessus、lynis 針對 Web/DB/Samba/防火牆掃描 CVE。searchsploit、metasploit)驗證可被入侵路徑。核心邏輯:你能找到的洞,駭客也能找到。**立即修補、驗證修補有效、記錄整改紀錄**。
linux-distros、oss-security 郵件列表、廠商安全公告(RHSA、DSA、USN)。dnf-automatic/unattended-upgrades 套用安全更新。rsyslog → Logstash → Elasticsearch → Kibana,設定關鍵字告警。安全非產品,是持續過程。七步建立基線,持續運營提升高度。記住:**沒有絕對安全,只有可管理的風險**。