1

我想创建原始 pg_hba.conf 文件的备份(可能是 pg_hba.conf.bk),然后在现有的 pg_hba.conf 文件中添加一个条目。到目前为止,这是我一直在尝试做的,但每次它说权限被拒绝,即使我通过 root 用户或使用 sudo。

我的尝试:

$ pg_conftool -s 10 main show hba_file
[OUT] /etc/postgresql/10/main/pg_hba.conf

$ sudo cat /etc/postgresql/10/main/pg_hba.conf
    [OUT] local   all             postgres                              peer
          local   all             all                                   md5
          host    all             all             127.0.0.1/32          md5
          host    all             all             ::1/128               md5

现在当我尝试在其中添加一行时,我收到权限被拒绝错误

$ sudo echo "host all all 0.0.0.0/0 trust" >> /etc/postgresql/10/main/pg_hba.conf
[OUT] bash: /etc/postgresql/10/main/pg_hba.conf: Permission denied

这将是部署脚本的一部分,因此,我真的不能手动进入 pg_hba.conf。那么,我怎样才能进入 conf 文件呢?

4

1 回答 1

2

您编写命令的方式,重定向>>将在命令之外sudo,因此以普通用户的权限执行。因此出现错误消息。

试试这个命令行:

sudo sh -c 'echo "host all all 0.0.0.0/0 trust" >> /etc/postgresql/10/main/pg_hba.conf'
于 2018-04-24T06:26:04.313 回答