Introduction

I wrote a document about installing Alpine Linux on an Android device some time ago. Here is how I am actually using it.

This document is not yet finished and I will update it continuously! It is a work in progress. A braindump actually… ;)

Here I describe how to set up a full hacking environment using a cheap (20$ - 60$) Samsung tablet.

Linux on AndroidI am using a Samsung SM-T585 tablet with 32GB of internal storage and a custom ROM for Samsung Galaxy Tab A 10.1 2016 (SM-T585) installed. After OS installation I have rooted this device using Magisk even when it is not secure, but I only use this device for development/hacking and there is no private data stored on the device. I will not explain the installation and/or rooting of custom ROM’s here! Installing a custom ROM and rooting the device is not required to use Linux on Android, but the “su” part will not work!

So, why I am rooting my device? That’s easy to answer. I want full access to everything! :)

After my finished setup, I have a full root user environment with the Zsh shell as default shell. This is possible using the Zsh from Termux… I can use all programs installed via Termux as root user. \o/

I will test the whole procedure on a stock Samsung Android ROM in a few days. Maybe I will root the stock ROM too, but I don’t know if that really works…

At first I need Termux installed on the tablet. I recommend to use F-Droid for installing apps. I don’t know if Termux is the same in the Google Play Store, so I just don’t use it from there.

Installation

This list may be incomplete. Please report errors!

  1. Install Termux
  2. Open Termux
  3. echo nameserver 9.9.9.9 > ../usr/etc/resolv.conf
  4. echo nameserver 149.112.112.112 >> ../usr/etc/resolv.conf
  5. Do default configuration of Termux by following the instructions
  6. Update Termux and install required packages
    • pkg upgrade
    • pkg add 7z
    • pkg add mc
    • pkg add net-tools
    • pkg add openssh
    • pkg add proot-distro
    • pkg add termux-auth
    • pkg add termux-tools
    • pkg add vim
    • pkg add wget
    • pkg add zsh
    • pkg add zsh-completions
  7. termux-setup-storage
  8. wget https://hanez.org/files/home.7z
  9. 7z x home.7z
  10. echo export PATH=/data/data/com.termux/files/home/bin:/data/data/com.termux/files/usr/bin > .penv
  11. chsh -s zsh
  12. su -
    1. hostname hacked-sm-t585 # This will be reset to “localhost” on a reboot!
    2. mkdir /data/root
    3. cd /data/root
    4. cp /data/data/com.termux/files/home/home.7z /data/root/
    5. 7z x home.7z
    6. rm -f home.7z
    7. echo export PATH=/data/root/bin:/data/data/com.termux/files/usr/bin:/system/bin > .penv
    8. echo cd /data/root >> .penv
    9. exit
  13. rm -f home.7z
  14. exit # This exits Termux.
  15. Open Termux and have fun…!
  16. su.sh # This makes you root with a nice configured environment… ;)

Linux distribution installation

I will show the installation of Alpine Linux here, but there are more distributions available. You can see available distributions using the command “proot-distro list”. Actually you can select the following distributions for installation:

Adélie Linux, Alpine Linux, Arch Linux, Artix Linux, Chimera Linux, Debian (bookworm), deepin, Fedora, Manjaro, OpenSUSE, Pardus, Rocky Linux, Ubuntu (24.04), and Void Linux

To be honest, we are not installing Linux here. Android provides the Linux Kernel. We are just installing a Linux distribution’s filesystem tre and are then “prooting” to it.

  1. Open Termux
  2. proot-distro install alpine
  3. proot-distro login alpine
    1. echo nameserver 9.9.9.9 > /etc/resolv.conf
    2. echo nameserver 149.112.112.112 >> /etc/resolv.conf
    3. apk update
    4. apk upgrade –available
    5. apk add 7zip
    6. apk add mc
    7. apk add vim
    8. apk add wget
    9. apk add zsh
    10. apk add zsh-completions
    11. apk add zsh-vcs
    12. chsh -s zsh
    13. wget https://hanez.org/files/home.7z
    14. 7z x home.cfg
    15. rm -f home.cfg
    16. echo export PATH=/root/bin:\$PATH > .penv
    17. exit
  4. proot-distro login alpine
  5. Have fun!

SSH server

  1. Start Termux
  2. passwd
  3. sshd

By default in Termux the SSH daemon is listening on port 8022 as you can not open ports below 1001 in Termux as you are not root here. You can see the username in Termux at the lower left corner of the terminal or by running the “id” command and you can get the IP address by running “ifconfig”.

On the client

# ssh -p 8022 u0_a162@192.168.0.42

Links

  • Android - A mobile operating system based on a modified version of the Linux kernel and other open-source software
  • F-Droid - An installable catalogue of FOSS (Free and Open Source Software) applications for the Android platform
  • PRoot - A user-space implementation of chroot, mount –bind, and binfmt_misc
  • PRoot Distro - A Bash script wrapper for utility proot for easy management of chroot-based Linux distribution installations
  • Quad9 - A free service that replaces your default ISP or enterprise Domain Name Server (DNS) configuration
  • Termux - An Android terminal emulator and Linux environment app that works directly with no rooting or setup required
  • Zsh - A shell designed for interactive use, although it is also a powerful scripting language

Comments