Introduction

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

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

I 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 we need Termux installed on the tablet. Use F-Droid for installing Termux!

WARNING! Do not install Termux from the Google Play Store!

It is different and causes a lot of problems… I told you so.

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 wanted and some required packages:
    • pkg upgrade
    • pkg add p7zip
    • 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
    • pkg add git
    • pkg add tmux
    • pkg add rsync
  7. termux-setup-storage
  8. wget https://hanez.org/files/home.7z
  9. 7z x home.7z
  10. echo export EDITOR=/data/data/com.termux/files/usr/bin/vim > .penv
  11. echo export PATH=/data/data/com.termux/files/home/bin:/data/data/com.termux/files/usr/bin:/system/bin >> .penv
  12. echo export SHELL=/data/data/com.termux/files/usr/bin/zsh >> .penv
  13. chsh -s zsh
  14. su -

    The su part is a bit hacky at the moment. I am working on fixing this… ;)

    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. /data/data/com.termux/files/usr/bin/7z x home.7z
    6. rm -f home.7z
    7. echo export EDITOR=/data/data/com.termux/files/usr/bin/vim > .penv
    8. echo export PATH=/data/root/bin:/data/data/com.termux/files/usr/bin:/system/bin >> .penv
    9. echo export SHELL=/data/data/com.termux/files/usr/bin/zsh >> .penv
    10. echo cd /data/root >> .penv
    11. exit
  15. rm -f home.7z
  16. exit # This exits Termux.
  17. Open Termux and have fun…!
  18. su.sh # This makes you become root with a nice pre-configured environment. Simply “su -“ will not work after this setup anymore; I will figure out why, but I don’t care actually… ;)

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 install”.

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 tree 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 wget
    8. apk add zsh
    9. apk add zsh-completions
    10. apk add zsh-vcs
    11. chsh -s zsh
    12. wget https://hanez.org/files/home.7z
    13. 7z x home.7z
    14. rm -f home.7z
    15. echo export PATH=/root/bin:\$PATH > .penv
    16. 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 u0_a162@192.168.0.42 -p 8022

Links

  • Alpine - A security-oriented, lightweight Linux distribution based on musl libc and busybox
  • 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