Running one Python program from another as a different user

Paul Rubin http
Fri Aug 12 20:21:28 EDT 2005

"dwelch91 at" <dwelch91 at> writes:
> This is on Linux... I have a daemon running as root and I want to
> execute another Python program as another user (a regular user). I have
> the name of the user and can use the 'pwd' and 'grp' modules to get
> that user's user and group ids. What I don't understand is how to then
> go about launching that new program.

Use os.fork to start a new process and have the new process do
os.setuid to the new user.  Then os.execl (or whatever) to run the 
target program.

More information about the Python-list mailing list