gpt4 book ai didi

linux - 如何安全地配置 pg_hba.conf postgresql.conf 以连接到 postgresql 数据库服务器

转载 作者:太空宇宙 更新时间:2023-11-04 12:51:03 26 4
gpt4 key购买 nike

我想配置我的 DigitalOcean Postgresql 数据库,以便在家里使用 pg_dumb,但我无法让它正常工作:

它与 pg_hba-conf 一起工作:

host all all all md5

并在 postgresaql.conf 中

listen_addresses = '*'

但我不想使用“all”和“*”,因为我猜这不安全。

我认为,在阅读了 Postgresql 文档(pg_hba.confauthentication 等等...)后,我应该在这两个文件中使用我的 IP:

  • pg_hba.conf: host all all xxx.xxx.xx.xx/32 md5

  • postgresql.conf: listen_addresses = 'localhost,xxx.xxx.xx.xx'

但我无法理解这个问题:

  1. 如果我把 listen_addresses='*' 放在 postgresql.conf 里,我在 pg_hba.conf 里放什么 IP 都没有关系! 它适用于任何 ip ¿?¿?例如 host all all 113.147.107.52/0 md5
  2. 如果我将 listen_addresses='localhost,[my_IP]' 放在 postgresql.conf 中,它不起作用:连接到数据库“c..ion”失败: 无法连接到服务器:连接被拒绝

    [my_IP] 中,我输入了从 ipecho.net 获得的 Ip,Ip 正确吗?

这是 pg_hba.conf,最后一个条目是我想只允许我访问的内容

# Database administrative login by Unix domain socket
local all postgres md5

# TYPE DATABASE USER ADDRESS METHOD

# "local" is for Unix domain socket connections only
local all rails peer
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5

# For copy from home with pg_dumb, this IP is random: all IPs allow me to execute pg_dum if in listen_address='*'
host all all my_ip_from_ipecho.net/32 md5

我想我需要更多的IP知识,除此之外我完全迷路了

( PD:最后,我想我会在服务器中执行 pg_dump,然后,从我家里的 PC,我会用 scp 复制这些备份文件。但我想了解发生了什么以及它是如何工作的)

非常感谢

最佳答案

如果你想在 postgresql.conf 中指定 ip 地址,你将必须确认你的客户端将来自的所有 ip(包括在这种情况下你的 PC ip 或 VPN,如果你正在使用)。

这就是为什么当您使用“*”时它会起作用,因为它会监听来自所有 ip(包括您的)的客户端。

pg_hba.conf 将用作防火墙,因此您也需要在那里配置您的入口。

在你的情况下,我认为最好使用 listen_addresses='*' ,并在 pg_hba 中配置 ip 地址,因为参数 listen_addresses 需要在你想要更改它时重新启动。

pg_hba.conf: host all all xxx.xxx.xx.xx/0 md5
postgresql.conf: listen_addresses = '*'

如果您需要进一步的帮助来配置您的 pg_hba,请告诉我。

祝你好运!

注意:关于 listen_addresses 参数的更多信息 http://www.postgresql.org/docs/9.4/static/runtime-config-connection.html

关于linux - 如何安全地配置 pg_hba.conf postgresql.conf 以连接到 postgresql 数据库服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37163956/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com