It is better to run as little of the program as possible with elevated privileges. You can run the small part that needs more privilege via the subprocess.call()
function, e.g.
import subprocess
returncode = subprocess.call(["/usr/bin/sudo", "/usr/bin/id"])
More Related Contents:
- What are the risks of running ‘sudo pip’?
- Why is sudo not accepting my sudo password? [closed]
- Security of Python’s eval() on untrusted strings?
- Getting “Permission Denied” when running pip as root on my Mac
- I need to securely store a username and password in Python, what are my options? [closed]
- hash function in Python 3.3 returns different results between sessions
- Is distributing python source code in Docker secure?
- Hiding a password in a python script (insecure obfuscation only)
- Securely Erasing Password in Memory (Python)
- pip install: Please check the permissions and owner of that directory
- Python 3, Are there any known security holes in ast.literal_eval(node_or_string)?
- sudo pip install VS pip install –user
- Mark data as sensitive in python
- Is a SQLAlchemy query vulnerable to injection attacks?
- running a command as a super user from a python script
- Is this Python code vulnerable to SQL injection? (SQLite3)
- How to run sudo with Paramiko? (Python)
- Create a temporary FIFO (named pipe) in Python?
- Securely storing passwords for use in python script [duplicate]
- Encrypted and secure docker containers
- Google Authenticator implementation in Python
- Do CSRF attacks apply to API’s?
- What’s the purpose of Django setting ‘SECRET_KEY’?
- Why do I get a “referenced before assignment” error when assigning to a global variable in a function?
- How to make scipy.interpolate give an extrapolated result beyond the input range?
- logging with filters
- how can i show an irrational number to 100 decimal places in python?
- I’ve got an error when trying to create sound using pygame
- How do I read text from the Windows clipboard in Python?
- Python IMAP search using a subject encoded with utf-8