刚开始接触postgresql,安装后就有一个默认用户postgres,而且在启动postgresql后只能通过切换到linux的postgres用户才能登录数据库进行操作,和Mysql的登录认证居然不一样。查了好多资料才知道,原来有个pg_hba.conf的配置文件作登录限制。它的语法规则是这样的:

  local database user auth-method [auth-options]

  host database user address auth-method [auth-options]

  hostssl database user address auth-method [auth-options]

  hostnossl database user address auth-method [auth-options]

  host database user IP-address IP-mask auth-method [auth-options]

  hostssl database user IP-address IP-mask auth-method [auth-options]

  hostnossl database user IP-address IP-mask auth-method [auth-options]

第一列是连接的方式,local是通过本地的unix socket连接,host是通过IP地址连接。第二列是目标数据库,第三列是用户。最后一列是认证方式(关键点),总共支持11种认证方式:

  1. Trust Authentication

  2. Password Authentication

  3. GSSAPI Authentication

  4. SSPI Authentication

  5. Ident Authentication

  6. Peer Authentication

  7. LDAP Authentication

  8. RADIUS Authentication

  9. Certificate Authentication

  10. PAM Authentication

  11. BSD Authentication

其中最常见的就是peer,ident,password。

peer方式中,client必须和PostgreSQL在同一台机器上,并且需要当前系统用户和要登陆到PostgreSQL的用户名相同,就可以登陆。

ident与peer类似,不过peer只能在PostgreSQL本地使用,ident则可以跨主机使用。

其实我们最常用的方式是通过密码远程登陆:

password认证分为三种方式:scram-sha-256、md5、password。

这三种方式都用密码认证,区别是密码在PostgreSQL上存储的形式和登陆时密码的传输形式。

如:# IPv4 local connections: host all all 127.0.0.1/32 md5

注意:修改了pg_hba.conf之后,需要重启PostgreSQL,才会应用新配置。

最新文章

  1. 用mixin引入模块后, 方法重名的解析方法
  2. android 开发赚钱
  3. java二叉树的实现和遍历
  4. jquery-mobile的页面跳转和iscroll之间的兼容解决方法
  5. VS-Visual Studio-IIS Express 支持局域网访问
  6. HDU2829 Lawrence(斜率优化dp)
  7. 内核中读取UTC时间
  8. HTML5 push
  9. 电容式触摸控制器PCB布局
  10. 【经验分享】Hydra(爆破神器)使用方法
  11. Java中常用的正则表达式
  12. 第55章 API资源 - Identity Server 4 中文文档(v1.0.0)
  13. BZOJ 4196 软件包管理器
  14. koa中间件机制详解
  15. eclipse解决js提示
  16. javascript高级程序设计第3版——第二章使用javascript
  17. 问题 Duplicate entry '0' for key 'PRIMARY'
  18. HDU 1024 Max Sum Plus Plus (动态规划)
  19. Oracle中Blob和Clob
  20. 【树莓派】树莓派刷Android系统

热门文章

  1. mondrian 4.7 源码部署
  2. Rest接口和Thymeleaf的两个坑
  3. 跟我学ASP.NET MVC之八:SportsStrore移动设备
  4. windows命令中的cd
  5. Kafka基础
  6. python二维码生成器
  7. 理解 RxJava 的线程模型
  8. BZOJ_5180_[Baltic2016]Cities_ 斯坦纳树
  9. java集合框架之HashMap
  10. Java基础-单列设计模式