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 上进行基本安全加固的指南。根据具体需求,可能还需要进行更多的定制和优化。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>