Starting and Shutting Down a Ubuntu machine from Android

Specifically from an android phone. WOL apps are 2 dimes a dozen to start the server remotely (I am using PC Wake, simple and it works) but I found it harder to find an app to allow me to shut down the machine remotely (I can log in using an SSH client and type the command but it gets a bit tedious after a while). Either the app didn’t work, or it required something to run on the target machine.

I ended up settling for a halfway solution called SSH Remote Exec+ (the + is important, it replaces another app called SSH Remote Exec that is no longer being developed), which basically allows you to save scripts to run remotely via SSH (obviously you need an SSH server running on the target machine). Next I needed the syntax of the command to be able to run the shutdown command on Ubuntu without getting stuck at the password prompt that immediately follows.

I didn’t want to start editing my sudoers file and the below works fine (it requires me to store the password in the script for SSH Remote Exec+ but since I am already storing the same password in the connection information anyway…)

echo <password> | sudo -S shutdown -h now