hillpig的个人博客分享 http://blog.sciencenet.cn/u/hillpig 畅想ing,思考ing,前行ing Email:bluevaley@gmail.com

博文

postgresql中关于md5认证的使用

已有 7409 次阅读 2013-2-16 01:09 |个人分类:linux|系统分类:科研笔记| postgresq, md5, pwfile

DBA要做的事(假设作为root登录):
1.首先创建一个临时密码文件,用于执行initdb(注:假设数据库初始化超级管理员用户为postgres,数据库密码12345,该密码可能和os的登录密码不同):
[root@localhost ]# PWFILE=$(mktemp) && echo "12345" > ${PWFILE} && chown postgres:postgres ${PWFILE} && chmod 0600 ${PWFILE}
[root@localhost ]# su -c "/usr/bin/initdb /usr/local/pgsql/data -A md5 --pwfile=${PWFILE} -E UTF8" postgres
2.然后在postgres用户的$HOME目录下形成.pgpass文件:
[root@localhost ]# sed -i -e 's/^/*:*:*:postgres:/' ${PWFILE} && mv ${PWFILE} /usr/local/pgsql/.pgpass && chown postgres:postgres /usr/local/pgsql/.pgpass
[root@localhost ]# chmod 0600 /usr/local/pgsql/.pgpass
[root@localhost ]# rm $(mktemp)
即可。

参考:https://github.com/zynaps/setup/blob/master/platform,下面是其中的摘录:
pacman -S postgresql
sed -i -e '/^#PGROOT=/cPGROOT="/var/lib/postgres"' /etc/conf.d/postgresql
mkdir -p /var/lib/postgres && chown -R postgres:postgres /var/lib/postgres
PWFILE=`mktemp` && pwgen -A1Bn 16 > ${PWFILE} && chown postgres:postgres ${PWFILE}
sudo -i -u postgres initdb -A md5 --pwfile=${PWFILE} /var/lib/postgres/data
sed -i -e 's/^/*:*:*:postgres:/' ${PWFILE} && mv ${PWFILE} /root/.pgpass && chown root:root /root/.pgpass

systemctl enable postgresql.service


加我私人微信,交流技术。




https://wap.sciencenet.cn/blog-419883-662127.html

上一篇:RHEL下关闭某个端口
下一篇:Autoconf的一些链接
收藏 IP: 223.72.72.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...
扫一扫,分享此博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-5-20 22:33

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部