SSH connection to Android phone Termux - Android phone

foreword

When using an Android phone to run things, the screen is too small, and sometimes I am not used to the operation. However, we can open ssh and use SSH on the computer PC to remotely connect to termux on the mobile phone.

This tutorial mainly implements the installation of SSH on the Android mobile phone termux, and remotely connects to Termux through SSH on the computer. At the same time, do internal network penetration on Termux, use cpolar to create a secure tunnel to map port 22, and realize SSH remote connection to Termux outside, without public network IP, and without setting up routers, here is a simple implementation using the domestic internal network penetration tool cpolar.

1. Install ssh

Enter the command to install openssh directly, there will be a need to enter once in the middle: Y and then continue the installation

pkg install openssh

Start ssh, the open port defaults to 8022.

sshd

view username

whoami

You can see the user name u0_a33, this needs to be remembered!!!

image-20230509135411343

To change the password, enter the following command:, after entering, you will be prompted to enter a new password, just enter it as required.

passwd

image-20230509135850913

2. Install cpolar intranet penetration

cpolar supports the http/https/tcp protocol, which can be used permanently for free with unlimited traffic, no public IP, and no need to set up a router. After using it for a while, you will find that it can even implement small cloud services directly at home.

cpolar official website: https://www.cpolar.com

Create a sources.list.dfolder of:

mkdir -p $PREFIX/etc/apt/sources.list.d

Add cpolar to download source files

echo "deb [trusted=yes] http://termux.cpolar.com termux extras" >> $PREFIX/etc/apt/sources.list.d/cpolar.list

update warehouse

pkg update

install cpolar

pkg install cpolar

Install termux service, note: after the installation is complete, remember to close and restart termux to take effect!!

pkg install termux-services

After restarting termux, then start cpolar

sv up cpolar

Set up autostart

sv-enable cpolar

This is to stop the cpolar service

sv down cpolar

cpolar.yml main configuration file path location

$PREFIX/etc/cpolar/cpolar.yml

Then we enter in the mobile browser http://localhost:9200to see the cpolar management interface, and use the account registered on the cpolar official website to log in

image-20230509155942139

3. Remote ssh connection configuration

After logging in to the cpolar management interface on the mobile browser, we click on the tunnel management on the left dashboard - create a tunnel. Since the ssh connection defaults to port 22, we need to create a tcp tunnel pointing to port 22:

  • Tunnel name: customizable, be careful not to repeat
  • protocol: tcp
  • Local address: 8022 (termux ssh default port)
  • Domain Type: Choose a random domain name
  • Region: Select China VIP Top

click创建

image-20230509163326388

After creation, open the online tunnel list, view the generated random public network tcp address, and then copy the public network address. Note that tcp://there is no need to copy

image-20230509163540826

4. Public network remote connection

Open the connection tool, enter the public network address generated by cpolar, tcp://no input is required, the port number is the port number behind the public network address, click connect

image-20230509163906448

Then enter the user name and password, we enter the user name we saw above u0_a33(everyone is different, the actual one is subject to your own)

image-20230509164341555

then enter the password

image-20230509164302049

The connection is successful, and the remote connection termux is set up!

image-20230509164421309

5. Fixed remote connection address

The free temporary TCP data tunnel established above through cpolar successfully connects to the termux system through ssh. However, the TCP data tunnel at this time is still a random temporary TCP tunnel, and the port number will change every 24 hours. If we want this public network address to exist stably for a long time, we need further settings (since the fixed TCP tunnel will occupy cpolar server resources for a long time, so this service has to be included in the VIP project). Now, let us set up a TCP data tunnel that can exist stably for a long time.

To establish a stable TCP data tunnel, we must first log in to the cpolar official website预留 and enter the interface of the dashboard

20230517093303

In the reserved interface, find 保留的TCP地址the project. Under this item, we fill in some necessary information, including the tunnel name to identify the data tunnel, the area where the tunnel is used, and so on.

image-20230509165956924

After filling in the information, click 保留the button on the right to fix the tunnel in the background of the cpolar official website, and then cpolar will generate a tunnel tcp port

image-20230509170226731

Then we go back to the cpolar interface of the browser, open it 隧道列表, find the random temporary TCP tunnel created before, enter 编辑the page,

image-20230509170321276

  • Port Type Selection固定TCP端口
  • 预留的TCP地址Fill in the fixed TCP address that we have just successfully reserved in the background of the cpolar official website

Then click the button below 更新.

image-20230509170420115

Then check the online tunnel list again and find that the public network address corresponding to the ssh tunnel has become a fixed address reserved by our official website

image-20230509170500482

Open the connection tool, enter a fixed public network address, tcp://no input is required, the port number is the port number after the public network address, and then click Connect

image-20230509170812337

It can also be successfully connected, so a permanent ssh remote termux tcp connection method is set up!!

We only need to keep the tunnel online normally, and we can remotely connect and control termux through this fixed public network address through SSH. No public network IP or router is required.

image-20230509171243126

Reprinted from the article of cpolar pole cloud: public network SSH remote connection to Termux – computer uses Android Termux "no public network IP required"

Guess you like

Origin blog.csdn.net/m0_72165281/article/details/132675036