Managing Linux and Unix Servers Remotely with the Termux Android App

Managing Linux and Unix Servers remotely can sometimes be a challenge, but it can be done very effectively remotely with your Android Smartphone or Android Tablet using the Termux App. The Termux app was created by Fredrik Fornwall and it provides an Android Terminal and Linux Environment without the need for ROOT access to the device. For Linux/Unix veterans they can start using this app right out of the box, for Linux/Unix newbies, the app can also be very useful. Termux is based upon Debian Linux and uses the Debian Package Management System. The best use of Termux is from the command line, it is possible to do graphical apps with Termux, but not recommended due to the difficulty, CLICK HERE for more info. The best option to develop Android graphical apps is to use Android Studio, which is a free download from Google.

Termux is available for free from the Google Play Store.

Just about any command line application available to Debian Linux can also be installed and used with Termux. For applications not available as Debian packages, but available as source code compatible with Linux, those applications can be compiled and built on Termux using the GNU Compiler Collection (GCC). Also, Linux shell scripts will run on Termux which has a default bash shell like most other Linux distros. Termux also has options for SSH and SFTP with the OpenSSH package available for download and install.

As a quick note, Android is based upon the Linux operating system, often referred to as "Unix-like", and it is perfectly acceptable to access the command line on an Android device. There are many Android apps that will let you access the command line. iOS operating system for iPhones and iPads is also Unix based, being based upon BSD Unix. Since it is Unix based it also has a command line, but Apple bars all iOS users from being able to access the command line in iOS. It is possible to get a command line in iOS by breaking the security mechanism in iOS, called "Jailbreaking", but it is not recommended to "Jailbreak" your iOS device. "Jailbreaking" will make your warranty null and void, and also there is the chance of one wrong misstep turning your iOS device into a useless "brick".

In this blog post I will show how to install Debian packages, how to do some basic network diagnostics with NMAP, how to build and run software applications and shell scripts at the Command Line Interface (CLI), and also how to connect to remote Linux and Unix servers using SSH and transfer files with SFTP. Our examples will be run on a Samsung Galaxy Tab A Android Tablet, and also a Samsung Galaxy S9 Plus Android Smartphone, both with recent version Android 9 "Pie". And both of these devices are using my home 5 Ghz Wifi for internet, but also if needed both of these Android devices can work with cellular internet. The examples in this blog post should work with all Android devices that have the Termux app installed.

While it is possible to do app development with Termux. App developers should instead use the Android Studio graphical development environment, which is a free download from Google, to do app development. The primary and best uses of Termux are remote management of Linux and Unix servers, and also network diagnostics testing.

Note that in these examples, the virtual keyboard is not visible in the screenshots. That is because I am using an excellent Fintie bluetooth keyboard with the Samsung Galaxy Tab A tablet. However, Termux works equally well with no bluetooth keyboard, as it provides a virtual keyboard on the screen of the Android device.

Installs

First, we can start by installing the GNU Compiler Collection (GCC), which contains the gcc, g++, and clang compilers for C and C++ software. Clang itself is a front end for the gcc and g++ compilers. Enter the following command at the command line, and then answer Y for yes when prompted to continue the install.

$ pkg install clang

Next, we will install OpenSSH which will give us SSH and SFTP to use from the command line. We will then use SSH to connect to and login to our Unix or Linux servers, and use SFTP to transfer files to and from our servers:

$ pkg install openssh

Next, we will install the NANO text editor, which is much easier to use than VI. For many years VI was the standard non-graphical text editor on Unix, and later Linux. But many people complained about the difficulty of using VI. Alternately, NANO is a much better and easier to use option.

$ pkg install nano

Next, we will install tracepath, which will give us useful network diagnostic tools.

$ pkg install tracepath

Next, we will install NMAP, which is very useful for network and server diagnostics:

$ pkg install nmap

And finally, we will install DNSUTILS, which has useful tools for network diagnostics, including the very useful TRACEROUTE:

$ pkg install dnsutils

After all of our installs, we will run a few basic Linux commands to test Termux, we will do this on a Android Tablet, a Samsung Galaxy Tab A, with the Termux app installed:

Here are some of the basic Linux commands we can run at the Command Line Interface (CLI), get the directory contents with ls -al, get the hostname, get the operating system name with uname, and ping google.com to check it is alive:

Shell Scripts and Applications

One good thing to test out Termux is to use NANO to make a simple shell script called INTRO.SH, change the shell script to executable with the chmod command, and then run the shell script from the command line in Termux:

#!/data/data/com.termux/files/usr/bin/bash
 
# show home directory
echo
echo "My home directory is: "
echo $HOME
echo

# show present working directory
echo
echo "My present working directory is: "
pwd
echo

# show the user shell
echo
echo "My shell is: "
echo $SHELL
echo

# show the users environment
echo
echo "My environment is: "
env
echo

Here is the commands we will use to create and run our shell script INTRO.SH:

Next, we can test some simple C and C++ programs to ensure that the GNU Compiler Collection (GCC) we installed is working correctly, first we will create the following example C program with the NANO text editor, HELLO.C:

// Hello.c
//
// simple c application

#include <stdio.h>

#define NUMBER 10

int main()
{
     // loop printing hello
     for (int i = 0; i < NUMBER; i++)
     {
        printf("Hello World!!\n");
     }

     return 0;
}

We will use the following commands at the command line to create our HELLO.C application, compile the application using the gcc compiler, then run the executable:

$
$ nano Hello.c
$
$ gcc Hello.c -o chello
$
$ ./chello
Hello World!!
Hello World!!
Hello World!!
Hello World!!
Hello World!!
Hello World!!
Hello World!!
Hello World!!
Hello World!!
Hello World!!
$
$

Next, we will create a simple C++ program, HELLO.CPP, to test the g++ compiler at the command line with NANO:

// Hello.cpp
//
// simple c++ application

#include <iostream>

using namespace std;

#define NUMBER 10

int main()
{
	// loop printing hello
	for (int i = 0; i < NUMBER; i++)
	{
		cout << "Hello World!!" << endl;
	}

	return 0;
 }

We will use the following commands at the command line to create our C++ application, compile it using the g++ compiler, and run the executable.

$
$ nano Hello.cpp
$
$ g++ Hello.cpp -o cpphello
$
$ ./cpphello
Hello World!!
Hello World!!
Hello World!!
Hello World!!
Hello World!!
Hello World!!
Hello World!!
Hello World!!
Hello World!!
Hello World!!
$
$

Network Diagnostics with NSLOOKUP

When we have hostnames to work with and need to find out the IP addresses of those hostnames, we would use the NSLOOKUP command at the command line. In this example we are looking at the IPs for google.com and also michaelgworkman.com. Note that Google has more than one IP address, most likely due the millions and millions of visitors to the Google website each day:

Network Diagnostics with Traceroute

Sometimes a server is not down but still the website is not accessible on the public internet, the culprit could be a server upstream from the web server, like a Default Gateway Server, or a DMZ server, or a firewall server, or a load balancing server. If any of the upstream servers to a web server goes down, and there is no backup, that would make the web server lose its connection to the public internet. A good tool for finding this out is the TRACEROUTE tool. In this example we are doing a TRACEROUTE of google.com, note there are many NO REPLY coming back to our Samsung Galaxy Tablet. This is most likely due to the Google firewall blocking or disabling traces from the external public internet, out of good security practice:

In another example, we do a trace of michaelgworkman.com, which is hosted in the Microsoft Azure Cloud at their Eastern USA data center. Note we are also getting NO REPLY back from the Microsoft network, which could indicate that the Microsoft firewall has disabled or blocked external tracing. Also note the many AT&T nodes during the trace, this is due to my internet provider being AT&T:

Network Diagnostics with PING

A great, simple tool to use to see if a server is up or down is the PING tool. In this example we are pinging both google.com and also localhost (127.0.0.1), and we can clearly see the servers for these hostnames are alive and running. In our case it is the Samsung Galaxy Android Tablet at localhost responding to the ping request to 127.0.0.1 that the tablet itself sent out:

Network and Server Diagnostics with NMAP

NMAP is a powerful tool to scan servers with and do network diagnostics, at its default usage it returns you information about a server or node on the network such as open ports and also OS type.

One scenario that NMAP can discover is the web server is not down, but the website is not accessible, it could be the software that runs on port 80 (http) and also port 443 (https) that software is no longer running, and no longer listening on those ports, software like Apache and Microsoft IIS. But in some cases the web server is still up and running, this situation can easily be diagnosed with NMAP.

In our first example, we are doing default NMAP scans against localhost (127.0.0.1), which is our Samsung Galaxy Android tablet, and also michaelgworkman.com and google.com, correctly the NMAP scan shows no ports open on localhost (127.0.0.1) and only ports 80 (http) and ports 443 (https) for the google.com and michaelgworkman.com domains:

In our next NMAP example, we are going to designate verbose output using the -v flag, by default nmap only provides a brief amount of data on the scan subject, but designating verbose output can result in many more details about the scan subject. In this example we are doing a verbose scan of michaelgworkman.com:

In our next NMAP example, we show how to use one call to nmap to scan multiple hosts, either hostnames can be scanned, or also the IP address of the host can also be used. Both will work equally well:

In our next NMAP example, we show how multiple IP addresses can be used instead of hostnames:

And in our final NMAP Example, we show how to use a file for input, which is very useful if you get tired of scanning the same hosts/IPs each day and have to type in the hostnames and IP addresses each time. Use NANO to create a file called scanfile.txt, and then put the following hostnames and IP addresses in the file:

michaelgworkman.com
google.com
127.0.0.1
52.173.184.147

Then we run NMAP with the file we just created like in the following example:

That is it for our NMAP examples, but there is countless other ways to use NMAP to do network diagnostics and server evaluations. When you have the time check out this excellent resource on NMAP examples:
20 NMAP Examples by ShellHacks

And also the authoritative resource for NMAP is at NMAP DOT ORG:
Nmap.org

SSH Linux/Unix Login and SFTP File Transfer

Next we will show how to login to a Linux/Unix server across the internet using SSH at the command line. SSH establishes a secure, encrypted connection between server and client that is safe from being spied upon by cyber-criminals and other undesirable types.  For this example I am using my free NetBSD Unix shell account from SDF.ORG. Normally to login to a remote Linux/Unix server, you would enter the following at the command line, SSH USERNAME@HOSTNAME, in this example I am connecting to tty.sdf.org with my username on the server, mworkman72. After connecting from the command line, if it is a first time connection, you may be prompted to accept a new PKI key from the server. Just enter Y for that, and then you will be prompted for your password:

SSH allows you to login to your shell account you have on a Linux or Unix server. But to actually do file transfers, you would use the SFTP tool, also from the command line. SFTP establishes a secure, encrypted connection between server and client that is safe from eavesdropping. In our next example, we will use SFTP to retrieve my PuTTY PKI key from tty.sdf.org. To use the command you would do the following at the command line: SFTP USERNAME@HOSTNAME, then use the GET command to download a file, and/or use the PUT command to upload a file:

Font Size on Samsung Galaxy S9 Plus Android Smartphone

With the Samsung Galaxy Android Tablet, font size was ok and was not difficult to read, but on the Samsung Galaxy Android Smartphone, it was a different story entirely. The font size was very small and difficult to read. But that can easily be remedied with a few changes to settings on our Android Smartphone. In this next example we will see how to increase font size on an Android Smartphone from the settings.

First, we open settings on our Samsung Android Smartphone, by clicking the settings app. If the settings app is not visible on your phone, place your finger at the bottom of the display and swipe UP to view all apps, and you will find it there:

Next, we will choose DISPLAY in the list of settings options:

Then on the DISPLAY menu, we select FONT SIZE AND STYLE in the menu:

Next we will then get the following screen which will let us increase the Font size on our Android device to make the text more readable:

There is also a second way to increase the font size on an Android device, and that is to use the SCREEN ZOOM menu option on the Display menu in settings:

This is what our SCREEN ZOOM option looks like in the settings that will allow us to increase the zoom on our Android device, and therefore increase the font size:

And finally, this is the end result of increasing the Font size or increasing the Zoom on our Samsung Galaxy S9 Plus Android smartphone, definitely more readable, and showing the execution of some basic Linux commands using the Termux app with a virtual keyboard:

<

Summary

In this blog post, we detailed how to manage Linux and Unix servers, and do network diagnostics, both remotely using an Android mobile device and the Termux app. Termux is a very powerful and useful app that is easy to use, and for Linux/Unix veterans, is instantly usable right after install. Termux is also very useful for beginning Linux and Unix users. In my next blog post I will detail how to use a similar app called TERMIUS, which works on both iOS and also Android devices.

For those who wish to try out and learn Unix, there is a NetBSD Unix shell account available from SDF at http://sdf.org for $9 every 3 months. Also, a free OpenBSD Unix shell account is available on https://tilde.institute. There is free Linux offerings on the internet as well. A free Ubuntu Linux shell account is available at https://tilde.team. Many Linux versions are available as free downloads on the internet as well.

To see my Curriculum Vitae, go to Michael G Workman CV

To see my projects on Microsoft Azure DevOps, go to https://dev.azure.com/AbionTechnology/

To see my Posts and Answers on Stack Overflow, go to Michael G. Workman on Stack Overflow

 If you have any questions about CC++Microsoft C# .NET,  Microsoft Azure Cloud, Unix, Linux, and/or Mobile Apps, please feel free to contact me by email at:

michael.g.workman@outlook.com

Popular Posts