04-postgresql-9.6.1安全管理之pg_hba.conf配置(2017-06-12)
2017-06-12 17:43
1236 查看
1测试需求
2步骤
1检查192168181141上的postgresql数据库的postgres用户l密码
2修改密码为postgres
3配置192168181141的pg_hbaconf文件
4测试
5附加测试配置pgpass
备注:例如如下的配置,会按顺序从上往下执行。
0.0.0.0/32表示 允许地址在0.0.0.0-255.255.255.255范围内的客户端
192.168.1.0/24表示子网掩码为255.255.255.0,此时允许192.168.1.0-192.168.1.255范围内的客户端地址链接。
192.168.1.0/32表示IP为192.168.1.0
zabbix为192.168.181.138
格式:hostname:port:database:username:password
再次进行登录就可以不用密码了。
测试完成
2步骤
1检查192168181141上的postgresql数据库的postgres用户l密码
2修改密码为postgres
3配置192168181141的pg_hbaconf文件
4测试
5附加测试配置pgpass
1、测试需求
192.168.181.141上的postgresql数据库,192.168.1.138要无密码登录进来,192.168.181.181要md5登录2、步骤
1)检查192.168.181.141上的postgresql数据库的postgres用户l密码
postgres=# select pg_user.usename,pg_user.passwd from pg_user; usename | passwd ----------+---------- postgres | ******** (1 row) postgres=# select usename,passwd from pg_shadow; usename | passwd ----------+-------- postgres | (1 row) postgres=# select md5(''); md5 ---------------------------------- d41d8cd98f00b204e9800998ecf8427e (1 row) postgres=# select rolname,rolpassword from pg_authid; rolname | rolpassword -------------------+------------- postgres | pg_signal_backend | (2 rows) postgres=# select rolname,rolpassword from pg_authid; rolname | rolpassword -------------------+------------- postgres | pg_signal_backend | (2 rows)
2)修改密码为postgres
postgres=# ALTER USER postgres WITH PASSWORD 'postgres'; ALTER ROLE
3)配置192.168.181.141的pg_hba.conf文件。
host all all 192.168.181.180/32 md5 host all all 192.168.181.138/32 trust
备注:例如如下的配置,会按顺序从上往下执行。
# "local" is for Unix domain socket connections only local all all trust # IPv4 local connections: host all all 127.0.0.1/32 trust host replication postgres 192.168.1.145/32 trust host replication postgres 192.168.1.146/32 trust host all postgres 192.168.1.0/32 md5 host all all 0.0.0.0/0 md5
0.0.0.0/32表示 允许地址在0.0.0.0-255.255.255.255范围内的客户端
192.168.1.0/24表示子网掩码为255.255.255.0,此时允许192.168.1.0-192.168.1.255范围内的客户端地址链接。
192.168.1.0/32表示IP为192.168.1.0
4)测试
pg961为192.168.181.180[postgres@pg961 opt]$ psql -h 192.168.181.141 -p 5432 -U postgres Password for user postgres: psql (9.6.1) Type "help" for help. postgres=#
zabbix为192.168.181.138
[postgres@zabbix /]$psql -h 192.168.181.141 -p 5432 psql (9.5.4, 服务器 9.6.1) 警告:psql 主版本9.5,服务器主版本为9.6. 一些psql功能可能无法正常使用。 输入 "help" 来获取帮助信息. postgres=
5)附加测试:配置.pgpass
因为从192.168.181.180登录到192.168.181.141的数据库中,每次要输入密码。那么可以在/home/postgre/目录下建立一个文件格式:hostname:port:database:username:password
[postgres@pg961 opt]$ vim /home/postgres/.pgpass 192.168.181.141:5432:postgres:postgres:postgres
再次进行登录就可以不用密码了。
[postgres@pg961 opt]$ psql -h 192.168.181.141 -p 5432 -U postgres psql (9.6.1) Type "help" for help. postgres=#
测试完成
相关文章推荐
- [zz]pg_hba.conf 一种安全地配置策略
- Postgresql pg_hba.conf配置文件小结
- PostgreSQL pg_hba.conf 文件简析
- PostgreSQL远程数据库连接 && PostgreSQL pg_hba.conf 文件简析
- postgresql pg_hba.conf 文件
- PostgreSQL 连接问题 FATAL: no pg_hba.conf entry for host
- postgres访问认证配置文件pg_hba.conf
- PostgreSQL的 pg_hba.conf 文件简析
- PostgreSQL 连接问题 FATAL: no pg_hba.conf entry for host
- PostgreSQL pg_hba.conf 文件解析以及忘记密码的处理方法
- PostgreSQL启动过程中的那些事十五.一:pg_hba.conf的用法
- 程序链接PostgreSQL 时报错"no pg_hba.conf entry"
- postgresql 10 用SQL 读取pg_hba.conf文件的视图
- Postgresql:pg_hba.conf基于主机的客户端验证
- PostgreSQL pg_hba.conf 文件简析
- postgresql_pg_hba.conf 文件
- postgresql_pg_hba.conf 文件
- 从pg_hba.conf文件谈谈postgresql的连接认证
- PostgreSQL 连接问题 FATAL: no pg_hba.conf entry for host
- PostgreSQL pg_hba.conf 文件简析【转】