Skip to content

Modular Python to execute any subprocess commands as another user (not necessarily superuser/root)

Notifications You must be signed in to change notification settings

wesinator/python-sudo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

python-sudo

Modular Python to execute any subprocess commands as another user (not necessarily superuser/root)

calling sudo -u

Usage:

This module does not take a user password for security and efficiency reasons (aiming for no user interaction to run).

Configure the sudoers file to allow running commands as another user (not necessarily the superuser):

  • parent_user ALL=(run_user) NOPASSWD: ALL
from sudo import run_as_sudo

# run `whoami` from user 'user'
cmd = "whoami"
sudo_user = "user"

run_as_sudo(sudo_user, cmd)

# optional shell, timeout (secs)
run_as_sudo(sudo_user, cmd, shell=True, timeout=20)

About

Modular Python to execute any subprocess commands as another user (not necessarily superuser/root)

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages