Change user on UNIX

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Giampaolo Rodola'

    Change user on UNIX

    Hi all.
    Is there any way to su or login as a different user within a python
    script? I mainly need to temporarily impersonate another user to
    execute a command and then come back to the original user.
    I tried to google a little bit about it but I still didn't find a
    solution.


    Thanks in advance.

    --- Giampaolo

  • Jeffrey Froman

    #2
    Re: Change user on UNIX

    Giampaolo Rodola' wrote:
    I mainly need to temporarily impersonate another user to
    execute a command and then come back to the original user.
    If the script is run as root, you can freely impersonate other users with
    the os.seteuid() and os.setegid() methods.

    If the script is not run as root (either directly or through sudo, as
    suggested by other posters), then perhaps it should be.


    Jeffrey

    Comment

    Working...