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)
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:
- Open Termux Terminal.
- Update and Upgrade apt packages
$ pkg update -y && pkg upgrade -y - Install dependencies
$ pkg install openssh nmap termux-auth -y - Start SSH server:
$ sshd - 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 - 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 - To set password for the user, we can use passwd command:
$ passwd - 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 - 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. - Now a prompt will appear asking that do you want to connect to the device, enter yes.
- Enter your Termux user password to authenticate.
3. Using Automated python script - Termux-SSH:
Steps:
-
Open Termux terminal
-
Install Python
$ pkg install python
-
Install git package
$ pkg install git
-
copy the url from the address bar and clone the Termux-SSH
$ git clone https://github.com/dmdhrumilmistry/Termux-SSH
-
Change to Termux-ssh directory
$ cd Termux-SSH
-
Install required packages
$ python -m pip install -r requirements.txt
-
Run install python file
$ python install.py
-
Run main python file to start Termux-SSH
$ python main.py Use help in Termux-SSH to get commands list and their usage description.
$ Termux-SSH >> help
To start SSH server use :
$ Termux-SSH >> start
To connect to the device use:
$ Termux-SSH >> connect cmd
Use the output command to connect to the device from terminal.To close and exit the SSH server use:
$ Termux-SSH >> exit
To keep SSH server running in background and close Termux-SSH use:
$ Termux-SSH >> close
Comments
Post a Comment