In this post I will tell you about an Android app that is extremely useful to run commands remotely on a Linux computer: Hot Button SSH Command Widget. This application allows you to launch conveniently any command you want on a remote computer through SSH only with the push of a button on the screen of your mobile phone or tablet. This not only will facilitate automation of repetitive tasks, but also is very interesting from the perspective of security for the same reasons I exposed in my Automatically lock/unlock your screen by Bluetooth device proximity post. It will allow you for example to lock and unlock the screen without having to type your password again and again in sight of other people.
Hot Button SSH Command Widget app
This kind of apps (also available for iOS) can also be used to run commands on Mac OS X and Windows systems if they have SSH service available. Recommended reading: How to create a Windows SSH server.
There are other apps which associate actions to buttons to execute different SSH commands from your mobile device, but this in particular also allows to place those buttons as widgets in your Android app launcher, reason why you don’t have to run any other application before launching the commands you want, which will allow you to save time running them more quickly.
Basically what this app offers is the ability to create up to 30 different buttons and associate them with a command that will be run on the remote computer in the same way you would do it using a generic ssh client:
$ ssh user@remote_server "uname -a" Linux remote_server 4.4.0-79-generic #100-Ubuntu SMP Wed May 17 19:58:14 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
As configuration options you have both hostname of remote computer to which the command will be launched and your user access credentials, so you are not asked for username and password each time you press the button. Authentication is also allowed using RSA keys (actually any type of public key accepted by the remote server to which you want to connect). To do this you will have to generate a private key and copy it somewhere in your mobile’s sdcard in which it goes unnoticed, with a name that does not attract attention and if possible in a folder whose name begins with period (.) so that it is hidden.
Then add the public key paired with your private key to the ~/.ssh/authorized_keys file on the remote computer, so you can get your commands executed instantly as soon as you press the desired button.
Some useful command ideas to launch from your mobile
Here are some ideas of buttons that may be interesting to remote control your own PC if you are far from your workplace. Also if you are close to your computer they may be useful if the screen is locked or the monitor is off. This way you will save those extra seconds that your monitor will take to wake up and you to enter the password and unlock the screen:
|Desired Action||Example Command|
|Suspend||sudo /bin/systemctl suspend|
|Power off||sudo /bin/systemctl poweroff|
|Reboot||sudo /bin/systemctl restart|
|Unlock screen||sudo loginctl unlock-sessions (Plasma Desktop 5)
gnome-screensaver-command -d (Gnome)
cinnamon-screensaver-command -d (Cinnamon)
mate-screensaver-command -d (Mate Desktop)
pkill xscreensaver (other window managers)
|Audio mute/unmute||amixer -q -D pulse sset Master toggle|
Other example commands (ideas) that you can run on your local computer:
- Start/stop video recording from your webcam in order to keep an eye on your workplace when you are left
- Control your media player
- Change your favorite chat client’s status
Running commands that require root privileges
As you can see in the table above, there are commands that require root privileges to run. Although the app has a configuration option to launch commands as root, I prefer for security reasons to always disable SSH access to root. So I recommend to better run this kind of commands by adding an entry to the sudoers file. This will allow its execution using sudo without being asked for a password. For the previous examples the following lines should be added:
daniloaz ALL=(ALL) NOPASSWD:/bin/systemctl poweroff,/bin/systemctl halt,/bin/systemctl reboot,/bin/systemctl suspend daniloaz ALL=(ALL) NOPASSWD:/bin/loginctl lock-sessions,/bin/loginctl unlock-sessions
Other interesting ideas
This app can also be used to automate some actions that would otherwise require to manually establish connections to remote servers often.
- Stop/start an application that hangs frequently until you find a permanent solution that solves the problem.
- Receive a push notification on your mobile with a given command’s output.
- Restart an unresponsive server due to a huge and unusual increase in load.
- Clean up caches that fill up frequently.
- Implement a multifactor authentication mechanism (MFA).
The limit is your imagination! Can you think of any other example?