0

i want to give some user sudo access from my golang application. but in the sudoers file i saw the line "# This file MUST be edited with the 'visudo' command as root.". because when we edit sudoers file with visudo it will check for syntax error brfore saving the file to avoid misconfiguration of the file because misconfiguration of sudoers file will lead to SUDO Privilege Escalation.

Here my question is how can i edit this file from my golang application safely with visudo's syntax check? or is there any other ways to give sudo access to an user without editing sudoers file?

i was trying to edit /etc/sudoers file from my golang application.

Siva
  • 1
  • 1

1 Answers1

0

I have found an Solution For this case.

there is a option in visudo to check any file with sudoers syntax. you can use the following command to check syntax for a specific file visudo -c -f your file location this command will shows "parse ok" if the file syntax is ok otherwise it will show the error.

solution: instead on directly writting to /etc/sudoers file you can create temp file and write your modified data to the temp file. now check the syntax of the temp file using the above command. if everything is ok then write you changes to the /etc/sudoers file.

Siva
  • 1
  • 1