以下是Debian PostgreSQL數據庫的安全設置要點:
sudo apt update && sudo apt upgrade
修補漏洞。postgres
用戶設置強密碼:sudo -u postgres psql -c "ALTER USER postgres PASSWORD '新密碼';"
。postgresql.conf
:設置 listen_addresses
為 '*'
(需結合防火墻限制實際訪問IP),調整 max_connections
等參數。pg_hba.conf
:限制遠程訪問IP,推薦使用 md5
或 scram-sha-256
認證。postgresql.conf
中設置 ssl on
并指定證書路徑,需先生成證書。sudo ufw allow 5432/tcp
。postgresql.conf
中設置 log_statement='all'
等參數,定期分析日志。pg_dump
備份數據庫并存儲至安全位置,可結合cron實現自動化。postgres
用戶,刪除不必要的默認數據庫。參考來源: