因此,我建立了一个名为“文书工作”的用户,并使用了一个同名的数据库
postgres=# create role paperwork;
postgres=# create database paperwork;
postgres=# grant all privileges on database paperwork to paperwork;
postgres=# ALTER ROLE paperwork WITH LOGIN;
postgres=# ALTER ROLE paperwork WITH PASSWORD 'paperwork';
但这仍然让我无需密码即可以书面形式登录
[###@EMOO modules]$ psql --username=paperwork --host=localhost
psql (9.6.3)
Type "help" for help.
paperwork=> \q
当我强迫它使用密码时,它接受任何密码,包括空密码:
[###@EMOO modules]$ psql --username=paperwork --host=localhost --password
Password for user paperwork:
psql (9.6.3)
Type "help" for help.
当我打开pgadmin3并单击“文书工作”用户时,它似乎具有加密的密码。
-- Role: paperwork
-- DROP ROLE paperwork;
CREATE ROLE paperwork LOGIN
ENCRYPTED PASSWORD 'md585ff97314dbeb9953b989fd363a8e96f'
NOSUPERUSER INHERIT NOCREATEDB NOCREATEROLE NOREPLICATION;
另外,当我打开pgadmin3时,它询问我postgres密码,但是同样会接受任何东西作为postgres密码。(并且我记得在安装postgres时设置了postgres密码)如何进行设置,因此您需要正确的密码才能登录?还是这里有些背景让我完全想念?。。。例如密码,仅用于远程登录或有些怪异。谢谢。
编辑:我没有一个/usr/share/postgresql/pg_hba.conf(编辑:实际上,我只是找不到它,因为我没有在“ locate”命令上使用sudo),我从样本文件:/usr/share/postgresql/pg_hba.conf.sample
从这里得到了这个想法:http : //blog.mattsch.com/2012/05/19/postgresql-accepts-any-or-no-password-when-connecting/我尝试使其具有md5身份验证,但我仍然拥有同样的问题。我尝试的是下面的文件/usr/share/postgresql/pg_hba.conf
@authcomment@
# TYPE DATABASE USER ADDRESS METHOD
@remove-line-for-nolocal@# "local" is for Unix domain socket connections only
@remove-line-for-nolocal@local all all @authmethodlocal@
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
@remove-line-for-nolocal@#local replication @default_username@ @authmethodlocal@
#host replication @default_username@ 127.0.0.1/32 @authmethodhost@
#host replication @default_username@ ::1/128 @authmethodhost@
然后,我重新启动了postgresql,但仍然遇到相同的问题。
编辑:感谢Abelisto。该“ show config_file”命令(使用pgsql登录后)使我走上了正确的轨道。从我的Linux用户命令行运行的“ locate pg_hba.conf”没有权限在postgres目录中找到实际的配置文件:/ var / lib / postgres / data /用户“文书工作”在以下行上将/var/lib/postgres/data/pg_hba.conf中的“ trust”更改为“ md5”后,现在使用错误的密码拒绝了它:
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
可能只是想测试几件事就解决了。
我的原始帖子的TLDR:
确保已将postgres密码设置为您知道的密码:
[###@EMOO ~]$ psql -U postgres
psql (9.6.3)
Type "help" for help.
postgres=# ALTER ROLE postgres WITH PASSWORD 'postgres password';
找到你的pg_hba.conf
:
sudo updatedb
sudo locate pg_hba.conf
将您的“ trust”替换为“ md5” pg_hba.conf
:
重新启动PostgreSQL:
sudo systemctl restart postgresql
以身份登录postgres
并更改所需的任何用户密码。现在,如果用户未提供正确的密码,将被拒绝。
psql -U postgres
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句