在Debian系統上配置LNMP(Linux, Nginx, MySQL/MariaDB, PHP)環境時,安全性是一個重要的考慮因素。以下是一些關鍵的安全設置步驟:
確保系統處于最新狀態,安裝所有可用的安全更新。
sudo apt update
sudo apt upgrade
設置強密碼并強制用戶使用復雜密碼。
sudo apt install libpam-pwquality
sudo nano /etc/security/pwquality.conf
檢查并禁用不必要的網絡服務,降低攻擊面。
sudo systemctl list-units --type service --state=running
sudo systemctl disable service-name
使用防火墻限制入站和出站流量。
sudo apt install ufw
sudo ufw enable
sudo ufw allow OpenSSH
sudo ufw allow port 80/tcp
sudo ufw allow port 443/tcp
sudo nano /etc/ssh/sshd_config
# 更改端口號
Port 2222
# 禁用root登錄
PermitRootLogin no
# 使用SSH密鑰對
在安裝MySQL后,使用 mysql_secure_installation
命令進行安全設置。
mysql_secure_installation
在MySQL配置文件中設置 bind-address
為 127.0.0.1
,或者注釋掉這一行,以允許遠程訪問。
# 在 /etc/mysql/mysql.conf.d/mysqld.cnf 或 /etc/my.cnf 中找到并修改
bind-address = 127.0.0.1
使用工具如Logwatch或Fail2ban來自動監控并報告系統活動和安全事件。
sudo apt install logwatch
sudo apt install fail2ban
合理配置用戶權限,確保每個用戶只能訪問其需要的文件和目錄。
sudo useradd newuser
sudo usermod -aG sudo newuser
定期備份服務器上的重要數據和配置文件,以防數據丟失或損壞。
sudo apt installTimeshift
通過上述步驟,可以顯著提高Debian LNMP環境的安全性。建議定期審查和更新安全設置,以應對新的安全威脅。