I want to create a backup of the original pg_hba.conf file (may be as pg_hba.conf.bk) and then add an entry into the existing pg_hba.conf file. So far this is what i've been trying to do, but every time it says permission denied even if i go via root user or use sudo.
My attempt:
$ 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
now when i try adding a line into it, i get the permission denied error
$ 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
This will be a part of deployment script therefore, I can't really go and make the entry into the pg_hba.conf manually. So, how can i make an entry into the conf file?