Becoming root within a Python script

François Pinard pinard at iro.umontreal.ca
Fri Sep 24 00:29:02 EDT 1999


Mark Krischer <mkrisch at radiata.com> écrit:

> why don't you call the python script using sudo, or make a wrapper
> script that calls sudo <scriptname>.py

I would prefer not run the script as root, but just become root, here and
there, once in a while, in precise and unusual circumstances.  And give
the root password when those times come, and only then.  I'm not found on
running as root, and tend to dislike suid scripts, wrapped or not.  Ideally,
I would like not having, as a programmer, the impression that I'm leaving
the current script (even if the implementation does).  It is probable that
no easy solution exists, but I preferred to ask, just in case someone would
have had magic for it in some bag of tricks.  Only based on my experience,
my initial guess would be to say that there is no general nice solution,
even if in this case, I would like to be proven wrong :-).

Oh, I'm not stuck on this problem: I presume I can easily launch `su'
and just pour shell commands into it.  It's not so bad.  But if it were
pure Python, it would be nicer, and I would write less shell code...

-- 
François Pinard   http://www.iro.umontreal.ca/~pinard





More information about the Python-list mailing list