Updated: 1 year ago

Linux in Android

📱💻 Turn Your Old Android Phone into a Tiny Linux Server for Coding

So I had an old Android phone lying around collecting dust. I reset it, installed Python on it, and figured I'd document the process for others—especially for folks who don't have a Raspberry Pi or similar devices! (You can totally do this on your daily driver too, but like any app, it'll use some storage and battery.)

There are many ways to do this, but I'll walk you through two easy and well-known methods:

  1. Termux (simpler but more limited)
  2. UserLand (a bit more flexible)

1️⃣ Using Termux

Termux is easy to set up and doesn't need root access, but some features (like Docker) won't work unless your phone is rooted. For more flexibility, I'll show UserLand next.

  1. Install F-Droid .
  2. From F-Droid, install Termux (or from Google Play if you prefer, but it may have more limitations).

⚙️ Basic Linux Setup in Termux

Open Termux and run the following:

# Update Termux packages
pkg update && pkg upgrade
# Check battery status
pkg install termux-api && termux-battery-status
# Install SSH for remote terminal access
pkg install openssh
# Set a password for SSH
passwd
# Start the SSH service
sshd
# Find your phone's IP address (note the number after 'inet')
ifconfig | grep 'inet ' | grep -v '127.0.0.1'
# Keep Termux awake
termux-wake-lock

💻 Remote Access via Termius (mobile or desktop)

To connect to the phone's SSH, ensure that both your device and the phone are on the same network.

  1. Install Termius Android or Termius Windows , we'll use Android version but they've similar configurations.
  2. Tap ➕ → New Host :
    • Alias : Any name (e.g., your phone model)
    • IP Address : The one from ifconfig
    • Port : 8022
    • Username : username
    • Password : The one you set with passwd

Now you can SSH into your Android phone from your laptop or another phone!

🐍 Install Python & tmux

# Update Linux packages
apt update && apt upgrade -y
# Install latest Python
pkg install python
# Install tmux for multitasking
pkg install tmux
# Start a new tmux session (detach with Ctrl+B, then D)
tmux -u new-session -s mytmux
# Install speed test lib
pip install speedtest-cli
# Run speed test via Python
python3 -c "import subprocess; subprocess.run(['speedtest-cli', '--bytes'])"

You can even set a static IP for your phone via your router to avoid changing IPs every time.

If you face repo errors, update Termux repositories:

termux-change-repo

⚠️ Termux doesn't support Docker natively, but you might be able to use Podman (haven't tested it myself).

More on Termux:
📖 Termux Wiki

2️⃣ Using UserLand

Everything mentioned for Termux kinda applies here too.

  1. Install UserLand from F-Droid or Google Play .
  2. Choose a Linux distro to install (supports Alpine, Arch, Debian, Kali, Ubuntu). I used Ubuntu for simplicity.

UserLand will ask for storage permissions and then prompt you to set a username and password (up to 8 characters). You'll need this password every time you enter the terminal.

⚙️ Ubuntu Setup in UserLand

# Update packages
sudo apt update && sudo apt upgrade -y
# Install basic tools
sudo apt install -y lsb-release net-tools apt-utils tmux
# Install and configure SSH
sudo apt install -y openssh-server
# Set your password again
passwd
service ssh start

Note: You might see minor warnings using sudo without root, but it's generally safe to proceed.

🐍 Install Python & Rust

# Install Python
sudo apt install -y python3 python3-pip python3-venv
echo "✅ Installed Python version: $(python3 -V)"
# Install Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source ~/.cargo/env
echo "✅ Installed Rust: $(rustc -V) & Cargo: $(cargo -V)"

🐳 Install Docker

sudo apt update
sudo apt install -y docker.io
sudo systemctl enable docker
sudo systemctl start docker
docker --version