Am trying to execute below command using a non root user
echo ‘%pg_wheel ALL= /bin/su – postgres’ > /etc/sudoers.d/postgres
Getting below error :
bash: /etc/sudoers.d/postgres: Permission denied
>Solution :
No – you can’t access it without root, because if you could alter the sudo configuration without root, then a non-root user could give themselves root access.
However, if you have access to root via sudo, you can use the "write with tee" trick.
To do that, you’d reformat that command like this:
echo '%pg_wheel ALL= /bin/su - postgres' | sudo tee /etc/sudoers.d/postgres
Warning: Be careful when editing the sudo files manually – a tool like visudo will check the syntax of your sudo command, but editing it directly means that you can lock yourself out.