CentOS Minimal 是 CentOS 的一個精簡版本,僅包含系統必要的幾個基本軟件包,因此其體積相對較小,適合只需要基本功能的用戶或系統。以下是在 CentOS 7 Minimal 上進行安全加固的一些基本步驟:
修改 /etc/login.defs
文件:
vi /etc/login.defs
PASS_MAX_DAYS
:設置密碼最長使用天數(建議不小于 900 天)。PASS_MIN_DAYS
:設置密碼更改最小間隔天數(建議不小于 20 天)。PASS_MIN_LEN
:設置密碼最小長度(建議不小于 8 位)。PASS_WARN_AGE
:設置密碼過期提醒天數(建議不小于 70 天)。編輯 /etc/pam.d/system-auth
文件:
vi /etc/pam.d/system-auth
添加或修改以下行以提高密碼復雜度:
password requisite pam_pwquality.so retry=5 minlen=8 dcredit=-1 ucredit=-1 lcredit=-1 ocredit=-1
這將要求密碼至少 8 位,包含至少 1 個數字、1 個大寫字母、1 個小寫字母和 1 個特殊字符。
使用 firewalld
管理防火墻規則:
systemctl start firewalld
systemctl enable firewalld
開放必要端口,例如 HTTP(端口 80):
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload
查看當前開放端口:
firewall-cmd --zone=public --list-ports
檢查 SELinux 狀態:
getenforce
臨時關閉 SELinux(無需重啟):
setenforce 0
永久關閉 SELinux,編輯 /etc/selinux/config
文件,將 SELINUX=enforcing
改為 SELINUX=disabled
,然后重啟系統。
安裝并配置 SSH 服務:
yum install openssh-server
systemctl start sshd
systemctl enable sshd
禁用 root 用戶通過 SSH 登錄,編輯 /etc/ssh/sshd_config
文件,添加或修改以下行:
PermitRootLogin no
重啟 SSH 服務:
service sshd restart
配置自動更新(可選):
yum install yum-cron
systemctl start yum-cron
systemctl enable yum-cron
編輯 /etc/yum/yum-cron.conf
文件以配置自動更新策略。
以上步驟提供了在 CentOS 7 Minimal 上進行基本安全加固的指南。根據具體需求,可能還需要進行更多的定制和優化。