最小化安装
yum remove [unneeded-package]
定期更新系统
yum update -y
yum upgrade -y
启用SELinux
sestatus
setenforce 1
/etc/selinux/config
中SELINUX=enforcing
仅使用官方和可信源
yum repolist
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-*
配置yum安全选项
在/etc/yum.conf
中添加:
gpgcheck=1
localpkg_gpgcheck=1
repo_gpgcheck=1
限制root使用
/etc/ssh/sshd_config
中PermitRootLogin no
设置umask
/etc/profile
中添加umask 027
~/.bashrc
中添加umask 027
关键目录权限
chmod 750 /bin /sbin /usr/bin /usr/sbin
chmod 700 /boot /etc /lib /lib64 /root
配置文件完整性检查
yum install aide
aide --init
aide --check
启用firewalld
systemctl enable firewalld
systemctl start firewalld
基本规则
firewall-cmd --permanent --add-service=ssh
firewall-cmd --permanent --add-service=http
firewall-cmd --reload
安装ClamAV
yum install clamav clamav-update
freshclam # 更新病毒库
clamscan -r / # 全盘扫描
配置自动扫描
内核参数加固
在/etc/sysctl.conf
中添加:
kernel.exec-shield=1
kernel.randomize_va_space=2
net.ipv4.conf.all.rp_filter=1
net.ipv4.conf.default.rp_filter=1
禁用不必要服务
systemctl disable [unneeded-service]
systemctl stop [unneeded-service]
配置auditd
yum install audit
systemctl enable --now auditd
配置日志轮转
/etc/logrotate.conf
和/etc/logrotate.d/
配置安装和配置fail2ban
yum install epel-release
yum install fail2ban
systemctl enable fail2ban
systemctl start fail2ban
设置自动安全更新
yum install yum-cron
systemctl enable yum-cron
systemctl start yum-cron
定期安全检查
ps aux
netstat -tulnp
crontab -l
和/etc/cron.*
目录通过以上配置,可以显著降低CentOS系统被恶意软件自动安装的风险。请根据实际环境需求调整这些配置,并定期审查系统安全性。