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

This document is not yet finished and will be updated 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 16GB 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!

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.

Steps to reproduce

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 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:\$PATH” > .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:\$PATH” > .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… ;)

Let’s install Linux now

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:

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

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

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 id 1000 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@10.0.0.23

Some 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