在CentOS上部署LAMP(Linux, Apache, MySQL, PHP)环境时,确保其安全性至关重要。以下是一些关键的安全防护措施,可以帮助你加固CentOS LAMP环境:
sudo yum update -y
sudo sed -i 's/#PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config
ssh-keygen -t rsa -b 4096
ssh-copy-id username@server_ip
firewalld
或iptables
配置防火墙规则,限制对服务器的访问,只允许必要的端口对外开放。sudo yum install firewalld -y
sudo firewall-cmd --permanent --add-rich-rule 'rule family="ipv4" source IP "攻击IP" drop'
sudo firewall-cmd --reload
visudo
编辑/etc/sudoers
文件,设置sudo超时等。httpd.conf
中注释掉不需要的Apache模块。mysql_secure_installation
命令更改root密码。php.ini
中启用安全模式,限制PHP脚本的执行权限。eval()
、exec()
等。chmod
和chown
确保敏感文件和目录的权限设置正确。