CentOS是一种广泛使用的Linux发行版,其安全性配置尤为重要。以下是一些基本的CentOS安全配置步骤:
修改密码策略配置文件:
/etc/login.defs
文件,设置 PASS_MIN_DAYS
(密码修改的最小间隔时间)为7天,PASS_MAX_DAYS
(密码失效时间)为90天。/etc/security/pwquality.conf
文件,设置 minlen
(密码最小长度)、maxrepeat
(密码中允许的最大字符重复次数)、minclass
(密码中至少包含的字符类别数)等参数。禁止空密码登录:
/etc/ssh/sshd_config
文件,将 PermitEmptyPasswords
设置为 no
。设置SSH空闲超时退出时间:
/etc/ssh/sshd_config
文件中,设置 ClientAliveInterval
(SSH空闲超时时间)为300秒,ClientAliveCountMax
(客户端空闲超时退出次数)为0。禁止root登录:
/etc/ssh/sshd_config
文件中的 PermitRootLogin
设置为 no
。使用firewalld配置防火墙:
sudo yum install firewalld
sudo systemctl start firewalld
sudo systemctl enable firewalld
sudo firewall-cmd --permanent --add-port=80/tcp
(允许HTTP流量)sudo firewall-cmd --reload
定期更新系统:
sudo yum update
命令更新所有软件包,确保系统和软件包的最新状态。禁用不必要的超级用户:
/etc/passwd
文件,检测并锁定不必要的超级账户。删除不必要的账号和组:
adm
、lp
、sync
等。强化用户口令:
使用auditd服务进行安全审计:
sudo yum install auditd
sudo systemctl start auditd
启用并配置SELinux:
/etc/selinux/config
文件,将 SELINUX
设置为 enforcing
。通过上述配置,可以显著提高CentOS系统的安全性和稳定性。请根据实际需求和安全要求进行配置,并定期进行安全审计和更新。