1. find / -name pg_hba.conf
2. sudo vi /etc/postgresql/13/main/pg_hba.conf
3. 拉到最下面,把postgres所在行的md5改成trust
local all postgres md5

改后:
4. sudo service postgresql restart
5. 无需输入密码即可登陆:
psql -U postgres
psql (13.1 (Ubuntu 13.1-1.pgdg20.04+1))
Type "help" for help.
postgres=#
6. 设置密码"postgres"后退出
ALTER USER postgres WITH PASSWORD 'postgres';
\q
7. 最后把trust改回md5:sudo vi /etc/postgresql/13/main/pg_hba.conf
8. sudo service postgresql restart
9. 用密码postgres正常登陆
psql -U postgres
Password for user postgres:
psql (13.1 (Ubuntu 13.1-1.pgdg20.04+1))
Type "help" for help.
postgres=#
本文详细介绍了如何在Ubuntu系统中修改pg_hba.conf文件,将postgres用户的密码从md5更改为信任,然后设置并验证密码,最后恢复为md5安全模式。涉及步骤包括sudo操作、postgresql重启和密码管理。

1674

被折叠的 条评论
为什么被折叠?



