JustTrying
JustTrying

Reputation: 602

What is the best way to execute CGI scripts with root privileges?

As the title says, I'm looking for a method to run a CGI script (running on APACHE on Ubuntu) with root privileges.

In particular, some commands of the script can be executed by the current user (apache), but other commands need root privileges (as iptables).

I can also write "sub-scripts" containing these privileged commands, but the problem of executing them with root privileges still remains.

I'm also confused about wether to write the CGI in C or PERL or bash script language. Any suggestion?

Upvotes: 3

Views: 7881

Answers (1)

Igor Chubin
Igor Chubin

Reputation: 64563

The best method is to use sudo for such scripts. You must specify which commands can run the script in this case.

In /etc/sudoers:

wwwdata    ALL=(ALL) /usr/local/bin/allowed-operation

And then in the script:

sudo /usr/local/bin/allowed-operation

Upvotes: 2

Related Questions