Shutting down via the web

One of the annoying things about Ubuntu is the fact that you need to be an admin user to shutdown the PC. This makes sense if you are running a server, but not when you have a few PCs scattered throughout the house that you’d just like to shutdown quickly.

So, I found a way to enable this through Apache. Warning: this will allow anyone who browses to your PC to shut it down without prompting. So use carefully.

Basically, what you need to do is remove the need for admin/sudo access when shutting down as the www-data (Apache) user. To do this, you use a specific command called visudo which specially edits a file containing what commands require admin access.

In short, make sure that the last line in that file is the following:

www-data ALL= NOPASSWD: SHUTDOWN_CMDS

and that there is a line further up that says Cmnd_Alias SHUTDOWN_CMDS = /sbin/shutdown, /sbin/reboot, /sbin/halt.

Then, once this is done, you can have a shutdown.php that has the following code:

<?php
echo exec('sudo shutdown -h now');
?>

Q.E.D.

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s