Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can non root user access /etc/sudoers in linux?

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading