Tuesday, December 23, 2025

Want to use your old android phone as python flask web server?

I was exploring how I can use my old phone(with android 9) as webserver . I came across "Termux" which helped me achieve this. 

The first problem with install Termux is, it is not available on Google play store. I had to use f-droid store.

I went to f-droid site and installed the apk.

Here are the steps:

Setting up an SSH server in Termux allows you to access your Android device's command line remotely from another computer or device

Prerequisites

Ensure you have the latest version of Termux, preferably installed from F-Droid as the Play Store version is outdated.

Ensure both the Android device running Termux and the client device (your computer) are connected to the same local network (Wi-Fi or hotspot).

    Steps to Set Up the SSH Server

  1. Update packages: Open the Termux app and run the following commands to ensure all packages are up to date:
    pkg update && pkg upgrade -y
  2. Install OpenSSH: Install the OpenSSH package, which includes the sshd server daemon:
    pkg install openssh -y
  3. Set a password: You need a password for SSH login. This is the password for your Termux user (which is an Android user ID like u0_a123, not your phone's lock password):
    passwd
  4. Enter and confirm your new password when prompted.
  5. Find your username and IP address:Find your username (e.g., u0_a123):
    whoami
  6. Find your device's local IP address (look for the inet address under the wlan0 interface, typically something like 192.168.x.x):
    ip addr show
  7. Start the SSH server: Start the SSH daemon in Termux:
    sshd
    By default, the Termux SSH server listens on port 8022 (not the standard port 22, unless you have rooted your device and manually changed the configuration).
    Optional: Prevent Termux from sleeping: To ensure the server keeps running in the background, you should enable a partial wake lock in the Termux notification settings.

Connecting from Another Device

From your computer or another device on the same network, use an SSH client (like OpenSSH on Linux/macOS, or PuTTY/WSL on Windows) to connect. Replace <username> and <ip_address> with the values you found in step 4:

bash
ssh -p 8022 <username>@<ip_address>

When prompted, enter the password you set in step 3. You are now connected to your Android device's Termux environment via SSH.

To stop the server at any time, run:
pkill sshd




References:

https://wiki.termux.com/wiki/Main_Page



No comments: