Unable to execute "reboot" in cgi script
Hi,
I am trying to execute "reboot" command inside a cgi script but nothing happens. I am using 2.6.18-1.2798.fc6. My script /var/www/cgi-bin/reboot.cgi contains: --------------- reboot --------------- Executing the script from a remote client: http://192.168.15.43/cgi-bin/reboot.cgi /var/log/httpd/error_log gives me the error: [Tue Oct 30 18:36:58 2007] [error] [client 192.168.15.91] reboot: must be superuser. [Tue Oct 30 18:36:58 2007] [error] [client 192.168.15.91] Premature end of script headers: reboot.cgi How do I fix this? Thanks |
That would be because your apache user which is running apache does not have access privs to execute a system reboot. That would be a huge gaping security hole if any standard user could execute a system reboot remotely like that. Especially through apache.
If you want to add that support you'll need to add this to the sudoers file, assuming your apache user is "apache" ---> apache ALL=NOPASSWD: /sbin/reboot . How do you add this to the sudoers file you ask? 1) su - root 2) visudo 3) add this line in there -> apache ALL=NOPASSWD: /sbin/reboot 4) save the changes 5) now change your script to say "sudo reboot" |
This line is already there:
apache ALL=(ALL) NOPASSWD:ALL do I have to modify it to: apache ALL=NOPASSWD: /sbin/reboot |
gotcha!
1.) changed apache ALL=(ALL) NOPASSWD:ALL to apache ALL=(root) NOPASSWD:ALL 2.) added sudo before the reboot command in cgi scripts 3.) commented out "Defaults requiretty" in /etc/sudoers, else you will see, "sorry, you must have a tty to run sudo" |
Followed the steps given by jcaga. But still not able to implement it.
When i try to open localhost/cgi-bin/reboot.cgi following error comes:- Error 500 Internal Server Error /var/log/httpd/error_log gives me the error: Exec Format Error : Exec of ..cgi-bin/reboot.cgi failed reboot.cgi has 700 permission Any help please?? ---------- Post added 05-10-12 at 07:46 AM ---------- I forgot to mention i am using RHEL 5.6 |
All times are GMT -5. The time now is 04:36 PM. |