Skip to main content

SSH Server on Android

 

How to create a SSH server on Android

Termux-SSH:

Termux is one of the best ways to use SSH and perform many more other operations on Android. It is one of the powerful application for android. We can use Termux to open a SSH terminal that can be accessed over LAN using Termux-SSH a python script or using OpenSSH.

Setting up the Android Device:

1. Termux:

Install Termux on Android device using Google Play Store.
Termux : https://play.google.com/store/apps/details?id=com.termux&hl=en_IN&gl=US (Not Preferred)
Official Website: https://termux.com/ (Install using F-Droid)

2. Using OpenSSH:

  1. Open Termux Terminal.

  2. Update and Upgrade apt packages

    $ pkg update -y && pkg upgrade -y

  3. Install dependencies

    $ pkg install openssh nmap termux-auth -y

  4. Start SSH server:

    $ sshd

  5. Get port on which SSH server is running using nmap. SSH will be running as service oa-system on default tcp port 8022 whose state will be open.

    $ nmap localhost

    Output :

    Starting Nmap 7.91 ( https://nmap.org ) at 2021-08-05 16:02 IST
    Nmap scan report for localhost (127.0.0.1)
    Host is up (0.0061s latency).
    Not shown: 999 closed ports
    PORT     STATE SERVICE
    8022/tcp open  oa-system

    Nmap done: 1 IP address (1 host up) scanned in 1.27 seconds

  6. To connect to the android device over ssh we need user. we can use default user and password. To find the default username use:
    $ whoami

    Output:

    u0_a130

  7.  To set password for the user, we can use passwd command:
    $ passwd

  8. Find your local ip to connect from LAN device. use ifconfig command to get locally assigned ip by the router on wlan0 network.
    $ ifconfig wlan0

    Output:

    wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 192.168.137.63  netmask 255.255.255.0  broadcast 192.168.137.255

            .....
    from output inet is your local ip. In this case its 192.168.137.63



  9. Now we can connect to the Termux terminal using powershell, cmd or any other terminal. So open your desired terminal and connect to the Termux Terminal.
    Syntax: ssh [username]@[localip] -p [ssh_port]

    $ ssh u0_a130@192.168.137.63 -p 8022

    Note: Machine should have OpenSSH installed. visit OpenSSH website for installation and more info.



  10. Now a prompt will appear asking that do you want to connect to the device, enter yes.

  11. Enter your Termux user password to authenticate.

 

3. Using Automated python script - Termux-SSH:

Steps:

  1. Open Termux terminal

  2. Install Python

    $ pkg install python
  3. Install git package

    $ pkg install git
  4. copy the url from the address bar and clone the Termux-SSH

    $ git clone https://github.com/dmdhrumilmistry/Termux-SSH
  5. Change to Termux-ssh directory

    $ cd Termux-SSH
  6. Install required packages

    $ python -m pip install -r requirements.txt
  7. Run install python file

    $ python install.py
  8. Run main python file to start Termux-SSH

    $ python main.py


  9. Use help in Termux-SSH to get commands list and their usage description.

    $ Termux-SSH >> help


  10.  To start SSH server use :

    $ Termux-SSH >> start


  11. To connect to the device use:

    $ Termux-SSH >> connect cmd

    Use the output command to connect to the device from terminal.


  12. To close and exit the SSH server use:

    $ Termux-SSH >> exit


  13.  To keep SSH server running in background and close Termux-SSH use:

    $ Termux-SSH >> close

Comments

Popular posts from this blog

How to get started with C Programming

Getting Started with C There are several ways to start with any programming language. But in this post I'm gonna tell you how I started C as my first programming language. To get started with any language you must know why you need to learn that language. You can google to learn about "why do we need C language" . After you're done googling. you've must have learnt various reasons why do we need C.

Programming in C on Android

C is a powerful General Purpose Programming Language. Learning C could be beneficial as it is one of the basic but powerful language, there are several powerful tools which had been developed using C. The Python interpreter is written in C language known as CPython, Linux  OS was built using C, Android Kernels , MacOS and even Crunch a pentest password word list generator tool is built using C language. So to start with C programming, a newbie must have an Integrated Development Environment(IDE). It would be so difficult to write in a notepad. IDE can make things much simpler, makes every task like Compiling, Linking, Debugging easy to perform. Without an IDE it would be difficult for developer to mange a project. There are several IDE's for Windows, but the two popular ones are listed below with print screen: 1. Dev C++ Dev C++ Download link:  https://www.bloodshed.net/devcpp.html   2. Codeblocks Codeblocks  Download li...