以下是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:端口,确认连接加密且权限生效。
参考来源: