Forget Laptops—Use SSH on Termux to Control Your Servers on the Go

Learn how to set up SSH on Termux to securely connect and manage your Android device from a terminal. This guide covers installation, configuration, troubleshooting common SSH errors, and using the sshd -d debug mode for diagnostics.

Managing remote servers on a laptop sounds easy—until you’re stuck in traffic, away from your desk, or worse, dealing with a sudden issue at 2 AM with nothing but your phone. I’ve been there.

One time, a critical service went down while I was out, and all I had was my Android device. No laptop, no quick access to my usual SSH setup.

That’s when I realized the power of SSH on Termux—a lightweight yet powerful solution that lets you securely access and control remote servers straight from your phone.

With Termux, you don’t need a dedicated machine to handle server tasks. Whether you’re fixing a broken web app, pulling repo updates, or managing databases, SSH on Termux turns your phone into a sysadmin’s best friend.

This guide will walk you through setting up SSH, securing your connection, and tackling common issues—so the next time duty calls, you won’t need to scramble for a laptop.

Steps to Install and Configure an SSH Server on Termux

1. Update and Upgrade Packages

Before installing OpenSSH, ensure Termux is up-to-date:

pkg update && pkg upgrade -y

2. Install OpenSSH

Install the OpenSSH package to enable SSH server functionality:

pkg install openssh -y

3. Set a Password for SSH Login

Since Termux doesn’t have a default password, you need to create one:

passwd

4. Start the SSH Server

Launch the SSH server with the following command:

sshd

5. Check the SSH Server Status

Verify that the SSH server is running and note the assigned port:

ps aux | grep ssh

6. Find Your Local IP Address

You’ll need your device’s IP address to connect via SSH. Find it using:

ifconfig | grep inet

Look for an IP in the format 192.168.x.x or 10.x.x.x (local network).

7. Connect to Termux via SSH (from Another Device)

From a PC or another phone, use the following command (replace <your-ip> with the actual IP):

ssh username@<your-ip> -p 8022

The default SSH port in Termux is 8022, not 22.

8. Enable SSH Server to Start on Boot (Optional)

To start the SSH server automatically when Termux launches, add this to your .bashrc or .zshrc:

sshd

For added security, generate an SSH key and copy it to Termux:

Generate an SSH key on your computer:

ssh-keygen -t rsa -b 4096sshd

Copy the public key to Termux:

ssh-copy-id -p 8022 username@<your-ip>

If ssh-copy-id is unavailable, manually append the public key to ~/.ssh/authorized_keys.

10. Secure Your SSH Server (Optional)

Modify the SSH configuration file for better security:

nano $PREFIX/etc/ssh/sshd_config

Change the port (if necessary):

Port 8022

Disable password authentication (if using keys only):

PasswordAuthentication no

11. Restart the SSH Server for Changes to Take Effect

pkill sshd && sshd

Now, your Termux SSH server is properly installed, configured, and secured for remote access!

· · ─ ·𖥸· ─ · ·

Troubleshooting SSH Setup in Termux

When trying to set up SSH on Termux, you may encounter some common errors. Below are the most frequent issues and how to resolve them.

Error: Permission Denied, Unable to Bind to Port 22

If you try to bind SSH to port 22, you might see the following error:

Bind to port 22 on :: failed: Permission denied
Bind to port 22 on 0.0.0.0 failed: Permission denied

Cause: This happens because Termux doesn’t have root privileges to use port 22. SSH ports below 1024 are known as privileged ports and require root access to bind services. This is a security measure in Linux-based systems to prevent unauthorized users from running system-critical services. Since Termux does not run as root by default, you need to use a non-privileged port (e.g., 2222 instead of the default 22).

Solution:
Change the port to a non-privileged port above 1024 (e.g., 2222):

Port 2222

After editing the port in the configuration file, restart the SSH service:

sshd

· · ─ ·𖥸· ─ · ·

Error: SSHD Not Running

If SSHD fails to start or seems unresponsive, running it in debug mode can help:

sshd -d

Debug mode provides logs that can pinpoint the exact problem, whether it’s a configuration error or a permissions issue.

· · ─ ·𖥸· ─ · ·

Error: Unable to Bind to Any Address

If you receive this error:

Bind to address 0.0.0.0 failed: Permission denied

Ensure you’ve correctly set the port above 1024 in the configuration file. Additionally, check that no other process is using the selected port.

· · ─ ·𖥸· ─ · ·

Additional Troubleshooting for SSH on Termux

Error: Connection Refused

If your SSH connection is refused, verify that the SSH server is running by checking the process:

ps aux | grep sshd

If SSHD isn’t running, start it again:

sshd

Error: Server Listening on the Wrong Port

If you can’t connect to Termux, check if the server is listening on the correct port by running SSHD in debug mode:

sshd -d

This will display logs indicating the active port and any potential issues.


Port Already in Use Issue

Bind to port xxxx failed: Port already in use

Check What’s Using Port 2696

Run:

ss -tulnp | grep 2696

or

netstat -tulnp | grep 2696

This will show which process is using the port.

If this returns an empty string, do this:

Check for a Zombie SSH Process

Even if ss and lsof show nothing, an SSHD process might still be running. Try this:

ps aux | grep sshd

If you see any sshd processes, kill them:

pkill sshd

Then restart SSH:

sshd

· · ─ ·𖥸· ─ · ·

Conclusion

By following this guide on how to set up SSH on Termux, you’ll be able to access and control your Termux environment remotely. Whether you’re troubleshooting SSH errors or simply looking to connect via another device, these steps will ensure a smooth experience. Remember, SSH is a powerful tool for remote management, but make sure to configure it securely by changing the default port and using strong passwords.

Leave a Reply

Your email address will not be published. Required fields are marked *

Comments (

)

  1. Cay Horstmann

    Thanks for the instructions. With termux 0.118.1 on Android 15, you don’t need to set the port. It defaults to 8022. But you can’t use ip (https://github.com/termux/termux-app/issues/2993) to see your IP address. For me, ifconfig still worked.

    I feel it is also useful to add instructions for setting up public key authentication, as in https://wiki.termux.com/wiki/Remote_Access#Setting_up_public_key_authentication

    1. Sam Galope

      Thank you, Cay, for your insightful comment! I appreciate you pointing out that Termux 0.118.1 on Android 15 defaults to port 8022—this simplifies things considerably. Regarding the issue with ip, you’re absolutely right. I must have defaulted to my usual Linux utilities while writing, and I’ll revise the instructions to revert to the reliable ifconfig for Termux.

      As for setting up public key authentication, that’s a great suggestion! I’ve written a detailed guide on the topic here:
      How to Set Up SSH Key-Based Authentication for Remote Login Without a Password.

      Additionally, you might find this related article helpful for managing SSH sessions:
      How to Prevent SSH Session Timeout on macOS and Linux.

      Thanks again for the feedback—I’ll ensure the article reflects these updates soon! 😊

  2. Kilner

    Exceptional post but I was wondering if you could write a litte more on this topic? I’d be very thankful if you could elaborate a little bit further. Appreciate it!

    1. Sam Galope

      Thank you for your feedback! I’m glad you enjoyed the post. I’d be happy to elaborate more on this topic in a future article. If you’d like to stay updated with more content, feel free to check out our subscription page here. Appreciate your interest, and stay tuned for more details!