Shutdown Linux via the Web

So a problem I’ve had with a project I’ve worked on is how do you shutdown your Linux server (in our case a Raspberry Pi) when its a headless web server.

Headless: Running with no monitor, keyboard and mouse, its not a requirement of this method, but it creates the problem.

Solutions – So there are several solutions to this:

Login via SSH

Open a Terminal and SSH to the box, then run “poweroff“
Ohh but we have touchscreens!

SSH Keys

Were on Windows!


Client installer


So we want a server based ability to shutdown a Linux/Unix box such as a Raspberry Pi, or intact run any privileged command.
The obvious answer is give your apache user root privileges and get PHP to execute a poweroff.
But hang-on, before you go handing your keys to your web server, this is VERY DANGEROUS and basically opens your machine to attack.


PHP-Shutdown – Writes a temporary file
CRON Job – Runs Command check frequently
Command Check – Looks out for the temp files in /tmp and acts upon them.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s