我在用着postgresql
作为学习的一部分,我尝试更改登录方法以获得更安全的登录方法。例如使用scram-sha-256
代替md5
。我试图改变我的password_encryption
to scram-sha256
in postgresql.conf
文件,并更改pg_hba.conf
方法scram-sha-256
此外,您还可以看到以下配置中的更改:
# - Authentication -
#authentication_timeout = 1min # 1s-600s
password_encryption = scram-sha-256 # md5 or scram-sha-256
#db_user_namespace = off
and
# TYPE DATABASE USER ADDRESS METHOD
# IPv4 local connections:
host all all 127.0.0.1/32 scram-sha-256
# IPv6 local connections:
host all all ::1/128 scram-sha-256
# Allow replication connections from localhost, by a user with the
# replication privilege.
host replication all 127.0.0.1/32 scram-sha-256
host replication all ::1/128 scram-sha-256
然后重新启动服务器后,我尝试使用登录cmd
当我收到以下错误时:
C:\Users\amir>psql -U postgres postgres
Password for user postgres:
psql: error: could not connect to server: FATAL: password authentication failed for user "postgres"
我可以通过改变一切来解决问题md5
方法和忽略password_encryption
in postgresql.conf
文件。我该如何解决这个问题?我是否必须将配置更改为默认值,然后尝试创建用户并为其分配加密密码。
每个用户密码哈希值都保存在表中pg_authid
。它包括用于将密码转换为其哈希值的哈希算法。
设置时password_encryption
在 postgresql.conf 中,您正在设置默认加密,即创建用户或(重新)设置密码时使用的加密。桌子pg_authid
is not更新。
当更改 pg_hba.conf 时,您是说仅接受使用给定方法散列的密码。桌子pg_authid
is not更新。
里面有一个重要的注释doc https://www.postgresql.org/docs/current/auth-password.html:
为了简化从 md5 方法到更新的 SCRAM 方法的转换,如果
md5 被指定为 pg_hba.conf 中的方法,但用户的密码
服务器针对 SCRAM 进行加密(见下文),然后基于 SCRAM
将自动选择身份验证
所以解决办法是
- 从现有用户开始,md5
- 更新 postgres.conf 以使用 scram 并重新加载配置
- 重置用户密码:现在它将在 pg_authid 中保存为 scram
- 你仍然可以在 pg_hba.conf 中使用 md5
- 如果对从 md5 到 scram 的迁移感到满意,请更新 pg_hba.conf 以指定 scram 而不是 md5
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)