为 PostgreSQL 用户设置空白密码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5421807/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
set blank password for PostgreSQL user
提问by othman
I use postgresql command 'createuser myusername'. It prompts me for password always. If I leave password blank it gives an error that no password is specified.
我使用 postgresql 命令“createuser myusername”。它总是提示我输入密码。如果我将密码留空,则会出现未指定密码的错误。
I simply want to create a user with blank/no password and I'm not able to do it with Postgresql 9 under mac os x.
我只是想用空白/无密码创建一个用户,但我无法在 mac os x 下使用 Postgresql 9 来做到这一点。
What steps should I take to create a user with no password. The command always asks me to enter a password.
我应该采取哪些步骤来创建没有密码的用户。该命令总是要求我输入密码。
回答by nate c
You're barking up the wrong tree trying to fix this with createuser
. If you care to check the man
page for createuser
it will tell you that login will fail if you really need a password and set --no-password. createuser
actually just creates a user. It does notdecide how the user will have to authenticate.
您正在尝试使用createuser
. 如果您想检查man
页面,createuser
它会告诉您如果您确实需要密码并设置--no-password,登录将失败。createuser
实际上只是创建一个用户。它并不能决定用户如何有进行身份验证。
Authentication is handled mainly in pg_hba.conf
, which decides whether or not to require passwords at login. I've never run PostgreSQL on OS X. On Linux, my distro's stock conf looks like this:
身份验证主要在 中处理pg_hba.conf
,它决定登录时是否需要密码。我从来没有在 OS X 上运行过 PostgreSQL。在 Linux 上,我的发行版的股票配置看起来像这样:
# TYPE DATABASE USER CIDR-ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all ident
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
I would make sure you have something like the first line for for development access. Note: psql
will try to connect with a unix socket if there is no --host
option set. The second line would be used if you try to connect with psql --host localhost
我会确保你有类似第一行的东西用于开发访问。注意:psql
如果没有--host
设置选项,将尝试与 unix socket 连接。如果您尝试连接,将使用第二行psql --host localhost
回答by araqnid
Rather than creating a user with no password, create a .pgpass filewith the password in to have it automatically supplied. This will be respected by all applications that use libpq to connect, which is practically all of them except the JDBC driver and the .NET driver.
与其创建一个没有密码的用户,不如创建一个包含密码的.pgpass 文件以自动提供密码。所有使用 libpq 连接的应用程序都会遵守这一点,实际上除了 JDBC 驱动程序和 .NET 驱动程序之外的所有应用程序。
回答by Малъ Скрылевъ
The additional way (I prefere it) to change user's password for PG user is to login to postgres console (as a postgres
user on a local pc), and issue SQL request:
更改 PG 用户密码的另一种方式(我更喜欢)是登录 postgres 控制台(作为postgres
本地 PC 上的用户),并发出 SQL 请求:
$ sudo -u postgres psql -w
# ALTER USER postgres WITH PASSWORD '';
回答by McNally Paulo
postgres=# ALTER USER postgres WITH PASSWORD '';
NOTICE: empty string is not a valid password, clearing password
ALTER ROLE
postgres=#