Running Python scripts under a different user

Bernard Lebel 3dbernard at gmail.com
Fri May 26 11:22:58 EDT 2006


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.



Thanks in advance
Bernard



More information about the Python-list mailing list