postgres有多个认证方式, 如:LDAP, Kerberos, md5, trust等等, 因为本人工作环境中, 会使用到两种:
 1. md5
 2. trust
现在只记录这两种方式, 其它的到使用到再记录.
postgres的认证方式配置在于: /usr/local/pgsql/data/pg_hba.conf
如下是本人的postgres认证配置:
# "local" is for Unix domain socket connections only
local   all         all                               trust
# IPv4 local connections:
host    all         all         127.0.0.1/32          trust
trust与md5的区别.
在上篇学习笔记中, 知道了, jessinio用户连接到数据库是无需使用密码的, 再看一下例子, 了解两种认证方式的区别:
[jessinio@study ~]$ psql --host 127.0.0.1 -d jessinio -U pgsql
Welcome to psql 8.2.9, the PostgreSQL interactive terminal.
Type:  \copyright for distribution terms
       \h for help with SQL commands
       \? for help with psql commands
       \g or terminate with semicolon to execute query
       \q to quit
jessinio=# 
可以连接.
为什么呢? 条件有二:
 1. 127.0.0.1是使用了trust认证
 1. jessinio在createuser时设置用户的密码!
把pg_hba.conf的trust修改为md5后:
host    all         all         127.0.0.1/32          trust
重新连接:
[jessinio@study ~]$ psql --host 127.0.0.1 -d jessinio -U jessinio
Password for user jessinio:
要求输入输入密码了! 在createuser时没有指定密码, 现在怎么重新设置密码呢? 答案是使用pgsql这个superuser去干!
# psql -d jessinio -U pgsql
# alter user jessinio with password 'pgsql_password'; 
这样就重置密码了.
DBMSs都是建议不使用trust的.
在initdb的手册中写得:
--auth=authmethod
              This  option specifies the authentication method for local users
              used in pg_hba.conf. Do not use trust unless you trust all local
              users on your system. Trust is the default for ease of installa-
              tion.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.