What is the best practices for checking if the user of a Python script has root-like privileges?
Posted
by Paul Hoffman
on Stack Overflow
See other posts from Stack Overflow
or by Paul Hoffman
Published on 2010-05-10T22:31:05Z
Indexed on
2010/05/10
22:34 UTC
Read the original article
Hit count: 386
I have a Python script that will be doing a lot of things that would require root-level privileges, such as moving files in /etc, installing with apt-get, and so on. I currently have:
if os.geteuid() != 0:
exit("You need to have root privileges to run this script.\nPlease try again, this time using 'sudo'. Exiting.")
Is this the best way to do the check? Are there other best practices?
© Stack Overflow or respective owner