Skip to main content

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

Project description

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):

sudo visudo:
  • 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)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

sudo-1.0.0-py3-none-any.whl (2.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page