Daniel López Azaña

Theme

Social Media

Blog

GNU/Linux, Open Source, Cloud Computing, DevOps and more...

Linux remote control from your smartphone via SSH button widgets

hot-button-ssh-command-widget-iconIn 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 ActionExample Command
Suspendsudo /bin/systemctl suspend
Power offsudo /bin/systemctl poweroff
Rebootsudo /bin/systemctl restart
Unlock screensudo 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/unmuteamixer -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
  • Etc.

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.

Some examples:

  • 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).
  • Etc.

The limit is your imagination! Can you think of any other example?

Daniel López Azaña

About the author

Daniel López Azaña

Tech entrepreneur and cloud architect with over 20 years of experience transforming infrastructures and automating processes.

Specialist in AI/LLM integration, Rust and Python development, and AWS & GCP architecture. Restless mind, idea generator, and passionate about technological innovation and AI.

Related articles

Ctrl+S

Unlock Linux command line after pressing Ctrl+s in Bash

Since the key combination Control+s is widely used as a shortcut to save files in GUI applications such as text editors, image editors, web browsers, etc. sometimes you are betrayed by your subconscious when you are working from the Linux command line and you use that same key combination when you are for example editing a Vim document when trying to save it. Then you notice that no key answers, the shell is locked and you can no longer do anything else in it.  Even worse, you get a cold sweat because you can’t continue editing your document and you can’t save the changes.

April 27, 2017
Partitioning example with GParted

The importance of properly partitioning a disk in Linux

I am a strong supporter of simplicity and the principle that less is more, but as far as security and performance of information systems is concerned, we must be able to strike a balance between keeping things simple and exposing ourselves as little as possible to potential threats while trying to obtain the maximum performance of all system elements involved.It is a common practice that the various distributions of Linux, and even the images used to launch Linux virtual server instances as in the case of AWS AMI’s, implement by default an extremely simple partitioning scheme consisting in a single partition that covers the entire disk. It is in this only partition where the root filesystem (/) is mounted and in which all the directories that configure the file hierarchy of a Linux operating system are placed.

March 15, 2016
linux-penguin-inside-a-box-tar-gz

15 most useful Linux commands for file system maintenance

One of the most common and tedious tasks of a sysadmin is to prevent file systems become completely full, because when a server runs out of space the consequences are unpredictable. Depending on how you structured the root file system and if it is divided into different partitions or volumes, those consequences will be more or less severe, but in any case undesirable.In any case it is always better to be safe than sorry, so use tools that perform automatic log rotation as logrotate and custom scripts to monitor and conduct periodic emptying actions to prevent file systems to get full. However, still using these prevention methods it is for sure it will be many times when you will have to act manually to troubleshoot problems.

October 1, 2014

Comments

Be the first to comment

Submit comment