Views:
228
Votes: 4
Tags:
python
sudo
Link:
🔍 See Original Answer on Stack Overflow ⧉ 🔗
URL:
https://stackoverflow.com/q/60292202
Title:
Ensure python script isn't run as root
ID:
/2020/02/19/Ensure-python-script-isn_t-run-as-root
Created:
February 19, 2020
Upload:
September 15, 2024
Layout: post
TOC:
false
Navigation: false
Copy to clipboard: false
Put this into your Python program/script:
#import os
if os.geteuid() == 0:
exit("You cannot call 'mmm' using using 'sudo' powers. Exiting.")
Of course you would replace mmm
with your own python filename.