以下是Debian上pgAdmin的安全設置步驟:
更新系統
sudo apt update && sudo apt upgrade
安裝pgAdmin
sudo apt install pgadmin4
配置pgAdmin
/etc/pgadmin4/config_local.py
,設置WEB_PORT
為其他端口(如5051)。sudo openssl req -newkey rsa:2048 -x509 -days 365 -keyout /etc/pgadmin4/server.key -out /etc/pgadmin4/server.crt
/etc/pgadmin4/config_local.py
,添加:SSL_CERTFILE = '/etc/pgadmin4/server.crt'
SSL_KEYFILE = '/etc/pgadmin4/server.key'
sudo systemctl restart pgadmin4
配置防火墻
使用ufw限制端口訪問(如允許5051端口):
sudo ufw allow 5051/tcp
sudo ufw enable
限制訪問權限
pg_hba.conf
中配置IP白名單,限制可訪問的客戶端IP。定期更新與監控
定期升級pgAdmin和PostgreSQL,使用工具(如Fail2ban)監控異常訪問。
驗證配置:通過瀏覽器訪問https://服務器IP:端口
,確認連接加密且權限生效。
參考來源: