0

Hi I start a python script by using python script.py.

But I need to write into a file which is inside the /usr/local/etc folder that requires permission of root. So I think I need to spawn a child process with sudo; the password to run the as sudo must be hardcoded into the script.

How do I do it?

Ralf
  • 16,086
  • 4
  • 44
  • 68
Darshu Bc
  • 526
  • 5
  • 22
  • Possible duplicate of https://stackoverflow.com/questions/22574201/running-python-script-as-root – saud Nov 23 '17 at 11:51
  • You can configure sudo so it does not require a password. You can also require the python script be started by root (that is, by "sudo script.py) and then use the os.setresuid call to change privileges for the necessary parts of the program. – mpez0 Jul 05 '18 at 13:43

0 Answers0