Running Python scripts under a different user

Diez B. Roggisch deets at nospam.web.de
Fri May 26 11:42:28 EDT 2006


Bernard Lebel schrieb:
> Hello,
> 
> I would like to know if there is a way to run a Python file under a
> different user account than the one logged in. Allow me to explain.
> 
> There are a bunch of people here, they are "basic user", with limited
> permissions. Basically there are locations on the network where they
> can only read and execute files, but no way to write.
> 
> Now, if these users want to write or modify files and directories,
> they would have to use my tools, which would control the permissions
> and allow the operations under parameters that I have defined.
> 
> Currently I see two ways of accomplishing this:
> 
> 1- the script changes the permissions of the locations the user is
> writing to, allowing the "basic user" to write to this location, and
> then restore the original permissions. What I don't like about this
> one, is that if the script stops, the locations may retain the writing
> permissions for the basic user.
> 
> 2- the script itself runs under a account with writing privileges (the
> power user), and network location permissions are not changed. If the
> script crashes, well, nothing to worry about as far as I can see.
> 
> 
> I could find in the Python library a way to do #1 easily (the os
> module), but failed to find anything for #2.

You didn't find anything there for a few reasons - mainly because if 
there was anything that made a program decide for itself which rights it 
wanted to run with, the whole concept of restrictive access would be 
kind of useless...


And as you refrain form telling us which OS you are running under one 
can only be very vague on what to suggest - UNIXish OSes have for 
example the setguid-bit, sudo springs to mind and under certain desktops 
there are ways to acquire root-settings (but you need a password then I 
guess)

Windows I don't know so much - but there exist the possibility to make a 
program run under a different user-account.

Diez



More information about the Python-list mailing list