Running Linux on android used to be a pain. You would have to root your device or download some broken emulator. As of today, running linux on Android is the easiest it has ever been thanks to the app Termux. Here’s how to run Linux on Android.
Open the app and type in the following commands:
pkg install proot-distro
That will install the proot-distro manager which makes it easy to manage multiple proot environments. Now go and install Ubuntu-20.04.
proot-distro install ubuntu-20.04
Finally, login to Ubuntu:
proot-distro login ubuntu-20.04
That’s it. You will now have a full linux operating system running on your Android device. This means you can run any Linux app on your android device (thanks to the seamless Qemu execution for incompatible CPU architectures.)
In order to setup SSH, you will have to change the port number and allow root login. Let’s go through the steps.
sudo apt-get update
Now install openssh-server
sudo apt-install openssh-server
Next, change your root password
Now open the sshd_config file in the nano editor.
Add the following line:
That is changing the default SSH port from 22 to 2022. Of course, it doesn’t have to be 2022 it could be any number you want that’s higher than 1024. We need to do this because your device is not rooted, therefore you can’t run a service on port 22 (reserved for system).
Finally, enable root login. I know, not the most secure thing to do. You could also setup a seperate account and login using that. But for this demo, we are just going to login using root. Add the following line:
Finally, save and exit the nano editor.
CRTL + O
CRTL + X
Now restart the SSH service.
service ssh restart
SSH from Client
Now to ssh from a SSH client do: ssh [email protected] -p 2022. If you don’t know your phone’s iP address, you can use the ifconfig or IP A command in the terminal to find your IP address. So for me I used the following command to SSH into my device:
ssh [email protected] -p 2022