我正在使用 postgresql 并且作为学习的一部分,我尝试更改为登录方法以获得更安全的登录方法。例如使用 scram-sha-256 而不是 md5。我尝试将 postgresql.conf 文件中的 password_encryption 更改为 scram-sha256,并将 pg_hba.conf METHOD 也更改为 scram-sha-256,您可以在下面的配置中看到更改:
# - Authentication -
#authentication_timeout = 1min # 1s-600s
password_encryption = scram-sha-256 # md5 or scram-sha-256
#db_user_namespace = off
和# 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 方法并忽略 postgresql.conf 文件中的 password_encryption 来解决问题。我该如何解决这个问题?我是否必须将配置更改为默认值然后尝试创建用户并为他们分配加密密码。
最佳答案
每个用户密码哈希都保存在表 pg_authid
中.它包括用于将密码转换为其散列的散列算法。
当设置 password_encryption
在 postgresql.conf 中,您正在设置默认加密,即在创建用户或(重新)设置密码时使用的加密。表pg_authid
是 不是 更新。
更改 pg_hba.conf 时,您是说只接受使用给定方法散列的密码。表pg_authid
是 不是 更新。
doc 中有一个重要的说明:
To ease transition from the md5 method to the newer SCRAM method, if md5 is specified as a method in pg_hba.conf but the user's password on the server is encrypted for SCRAM (see below), then SCRAM-based authentication will automatically be chosen instead
所以解决办法是
关于postgresql - 我试图将 postgresql md5 更改为 scram-sha-256,但我得到 FATAL 密码身份验证失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64316324/