PostgreSQL 配置文件 pg_hba.conf 安全管理配置
本文最后更新于 930 天前,其中的信息可能已经有所发展或是发生改变。

PostgreSQL 配置文件 pg_hba.conf 安全管理配置

该文件用于控制访问安全性,管理客户端对于PostgreSQL服务器的访问权限,内容包括:允许哪些用户连接到哪个数据库,允许哪些IP或者哪个网段的IP连接到本服务器,以及指定连接时使用的身份验证模式。

配置文件说明

该配置文件有5个参数,分别为:

TYPE(主机类型)、DATABASE(数据库名)、USER(用户名)、ADDRESS(IP地址和掩码)、METHOD(加密方法)
# TYPE  DATABASE        USER            ADDRESS                 METHOD
local   all             all                                     trust
host    all             all             127.0.0.1/32            trust

主机类型

  1. local匹配使用Unix域套接字的连接
  2. host匹配使用 TCP/IP建立的连接,同时匹配SSL和非SSL连接

认证方式

trust
    无条件地允许连接。
    允许任何可以与PostgreSQL数据库服务器连接的用户身份登入
    不需要口令或者其他任何认证。
reject
    无条件拒绝连接。常用于从一个组中“过滤出”特定主机
    例如一个reject行可以阻塞特定的主机连接,而后面一行允许特定网络中的其余主机进行连接
md5和password口令认证
    md5认证方式为双重md5加密,password指明文密码
    不能在非信任网络使用password方式。
peer
    从操作系统获得客户端的操作系统用户,并且检查它是否匹配被请求的数据库用户名
    只对本地连接可用

安全设置本地也需密码验证登录

因为默认配置如下,这样非常不安全,随便一个用户psql即可登录数据库。

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     trust
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
# IPv6 local connections:
host    all             all             ::1/128                 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local   replication     all                                     trust
#host    replication     all             127.0.0.1/32            trust
#host    replication     all             ::1/128                 trust
host    all             all             0.0.0.0/0               md5

修改

# TYPE  DATABASE        USER            ADDRESS                 METHOD
local   all             all                                     md5
host    all             all             127.0.0.1/32            md5
host    all             all             ::1/128                 md5
host    all             all             0.0.0.0/0               md5

保存pg_hba.conf文件,然后重新启动postgres数据库

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Image
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇