How To Prevent A PERL Script From Running As Root

At or near the top of your app, before it executes anything sensitive, place the following code:

if((getpwuid($<) eq "root") || ($< == 0)){ print STDOUT "Cannot run as root!\n"; exit(1); }

How to do this in Python: how-to-prevent-a-python-script-from-running-as-root

Did you find this post useful or have questions or comments? Please let me know!

This entry was posted in How Tos, perl, Programming. Bookmark the permalink.

One Response to How To Prevent A PERL Script From Running As Root

  1. Robert says:

    Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *