Python runs the command as a regular user in the root of the script

I have a python script that runs as root, I cannot change it.

I would like to know if it is possible to output some lines of this script (or all scripts) as a regular user (I do not need to be root to run it).

The reason is because I use notifications, and python-notify does not work on all machines in the root (it looks like this: bug )

So, do you know if it is possible to change it, with a subprocess or another?

thank

+4
source share
3 answers

I would like to know if it is possible to output certain lines of this script (or the entire script) as a regular user

, - .

Python os , , setegid. , , , Python; C .

POSIX , . . setuid seteuid, :

  • , seteuid, setreuid, , UID. , .
  • script , root, setresuid , .

Python 3.1 , . seteuid , setuid ... , , , , , root . POSIX, POSIX . , , , manpages, , , .

, , , ?

( , POSIX), . subprocess, multiprocessing, os.fork , setuid setresuid, - , , .

+5

getpwnam PWD , , os.setuid() python script .

import pwd, os
uid = pwd.getpwnam('username')[2] #instead of index 2 you can use pw_uid Attribute
os.setuid(uid)

, setuid .

+2

script root, os.setuid, UID () os.seteuid, UID ( reset EUID root).

, os.setuid , UID - , .

os.seteuid UID. UID - root, EUID root script.

+1

All Articles