Root access with python

Gustavo Niemeyer niemeyer at conectiva.com
Mon Mar 25 10:38:55 EST 2002


>>> On the terminal, you would do a 'su', type your password, then enter
>>> the command you wanted to run. How is this achieved within Python?
[...]
>>Instead, run "su" the usual way and type your password to get a root
>>shell, then launch your GUI app from the root shell.
> 
> Good advice.  Nevertheless, if Moray wants to shoot zirself in the foot,
> zie should take a look at os.setuid().

Fortunately, it's not that easy. os.setuid() is useful if you want to
drop privileges, not the other way around.

You have several options to do this, and all of them involve setting the
setuid bit in some executable. OTOH, setting setuid bit on scripts
usually doesn't work. If that's your case, you'll have to freeze your
script into a native executable, or build some kind of wrapper. Google
for "setuid bit scripts" for more information.

-- 
Gustavo Niemeyer

[ 2AAC 7928 0FBF 0299 5EB5  60E2 2253 B29A 6664 3A0C ]




More information about the Python-list mailing list