Banner of Remote Power at Your Fingertips: Learn How to Control Your PC via Termux and SSH

How I Control My PC from My Phone: A Guide Using Termux, SSH, and SSHpass


Category: Linux

Date: 10 months ago
Views: 941


Introduction

Hey there, fellow tech enthusiasts! Imagine having the power to control your PC right from the palm of your hand. Well, buckle up because I'm about to show you how I do just that using Termux, SSH, and SSHpass. Get ready to unlock a whole new level of convenience and productivity!

Setting Up Termux, SSH, and SSHpass

  1. Install Termux: First things first, head over to the Google Play Store or F-Droid and install Termux on your Android device. It's a powerful terminal emulator that's perfect for our needs.

  2. Install SSH: Once you've got Termux up and running, install the OpenSSH package using the package manager:

        
    pkg install openssh
        
    

  3. Install SSHpass: Additionally, install SSHpass, a handy tool for non-interactive SSH password authentication:

        
        pkg install sshpass
        
    

Setting Up SSH on Your PC

  1. Enable SSH: Now, let's head over to our PC running Arch Linux and enable SSH. If you haven't already, install the openssh package and start the SSH service:

        
        sudo pacman -S openssh
        
    

  2. Configure SSH: To ensure secure connections, let's configure SSH by setting up SSH keys for authentication. This adds an extra layer of security and convenience.

Connecting Your Phone to Your PC

  1. Find PC's IP Address: Open up a terminal in Termux and find your PC's local IP address using the ifconfig or ip addr command.

  2. Connect via SSH: With the IP address in hand, establish a connection to your PC from Termux using SSHpass. Use the following command, replacing "mylinuxpassword" with your actual password, myusername with your username, and 192.168.1.12 with your PC's IP address:

        
        ssh myusername@192.168.1.12
        
    
    This command will prompt for your password and establish a secure SSH connection to your PC.

after the first connection with ssh, you can skip the part of the password prompt everytime using sshpass like so:

    
sshpass -p "mylinuxpassword" ssh myusername@192.168.1.12
    
Screenshot ranger file manager
Screenshot: ranger file manager

Executing Commands from Your Phone

  1. Basic Commands: Start off by running some basic commands like ls, pwd, and date directly from your phone. It's like having a mini Linux terminal in your pocket!

  2. Running Custom Shell Scripts: Take things up a notch by running your own custom shell scripts stored on your PC. Whether it's controlling music playback with mpc or snapping photos with ffmpeg, the possibilities are endless.

As always, I created a simple alias for this whole command, therfore making connecting to my pc as efficient as possible. As an Arch linux user, almost all the daily commands and programs I use are actually my proper shell scripts. So for me, almost all the functionality of my pc can be used with this small command through my phone

Conclusion

By harnessing the power of Termux, SSH, and SSHpass, I've transformed my phone into a remote control for my PC. The convenience and productivity gains are undeniable, and I can't imagine going back. Give it a try, and unlock a whole new world of possibilities!

Additional Resources



941 views

Previous Article Next Article

0 Comments, latest

No comments.