Realize external network ssh remote connection to linux through cpolar

Now I have an idea, that is, I hope to be able to remotely connect to my development board through the external network. Here we need to use a technology, intranet penetration.

Intranet penetration is a technology that allows devices in the internal network to be accessed through the external network. In the linux system, there are many ways to achieve intranet penetration, the most common of which is to use ngrok and frp.

Take frp as an example. frp is a high-performance reverse proxy application focusing on intranet penetration. It supports TCP, UDP, HTTP, HTTPS and other protocols. Intranet services can be exposed to the public network through transit with public network IP nodes in a safe and convenient way.

However, since I do not have a public network IP, I use an intranet penetration software cpolar, which does not limit traffic and can be used for free forever. After completing the configuration of the software, the ssh tunnel will be installed by default. You only need to start it to get the ssh tunnel and map the public network address of port 22, which is relatively simple.

1. Intranet penetration

1.1 Register a free cpolar account

cpolarOfficial website address: https://i.cpolar.com/m/55wq, register an account on the official website. After registering the account, click User Settings in the upper right corner to reset AuthToken;

And save your own Authtoken;

20230111103532

1.2 Install cpolar client

Download the cpolar installation script:

root@rk3399:/data# mkdir cpolar
root@rk3399:/data# wget https://www.cpolar.com/static/downloads/install-release-cpolar.sh
root@rk3399:/data# mv install-release-cpolar.sh ./cpolar/
root@rk3399:/data# mv install-release-cpolar.sh ./cpolar/
root@rk3399:/data# cd cpolar/
root@rk3399:/data/cpolar# ls -l
total 24
-rw-r--r-- 1 root root 21833 Apr 5 2023 install-release-cpolar.sh
root@rk3399:/data/cpolar# chmod + x install-release-cpolar.sh

start installation:

root@rk3399:/data/cpolar# ./install-release-cpolar.sh
  % Total % Received % Xferd Average Speed Time Time Time Current
                                 Dload Upload Total Spent Left Speed
  0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 21833 100 21833 0 0 61849 0 --:--:-- --:--:-- --:--:-- 61849
info: Installing Cpolar 3.3.12 for aarch64
Downloading Cpolar archive: http://static.cpolar.com/downloads/releases/3.3.12/cpolar-stable-linux-arm64.zip
  % Total % Received % Xferd Average Speed Time Time Time Current
                                 Dload Upload Total Spent Left Speed
100 6716k 100 6716k 0 0 9.7M 0 --:--:-- --:--:-- --:--:-- 9995k
info: Extract the Cpolar package to /tmp/tmp.zNY8gPayfj and prepare it for installation.
Downloading Cpolar demo config file: http://static.cpolar.com/downloads/cpolar.demo.yml
  % Total % Received % Xferd Average Speed Time Time Time Current
                                 Dload Upload Total Spent Left Speed
100 186 100 186 0 0 4650 0 --:--:-- --:--:-- --:--:-- 4650
Downloading Cpolar service config file: http://static.cpolar.com/downloads/cpolar.service
  % Total % Received % Xferd Average Speed Time Time Time Current
                                 Dload Upload Total Spent Left Speed
100 384 100 384 0 0 11294 0 --:--:-- --:--:-- --:--:-- 11294
Downloading Cpolar service@ config file: http://static.cpolar.com/downloads/[email protected]
  % Total % Received % Xferd Average Speed Time Time Time Current
                                 Dload Upload Total Spent Left Speed
100 380 100 380 0 0 11875 0 --:--:-- --:--:-- --:--:-- 11875
rm: cannot remove '/etc/systemd/system/cpolar.service.d/10-donot_touch_multi_conf.conf': No such file or directory
rm: cannot remove '/etc/systemd/system/[email protected]/10-donot_touch_multi_conf.conf': No such file or directory
info: Systemd service files have been installed successfully!
warning: The following are the actual parameters for the cpolar service startup.
warning: Please make sure the configuration file path is correctly set.
# /etc/systemd/system/cpolar.service
[Unit]
Description=Cpolar Service
Documentation=https://www.cpolar.com/docs
After=network.target nss-lookup.target

[Service]
User=nobody
NoNewPrivileges=true
ExecStart=/usr/local/bin/cpolar start-all -dashboard=on -daemon=on -config=/usr/local/etc/cpolar/cpolar.yml -log=/var/log/cpolar/access.log
Restart=on-failure
RestartPreventExitStatus=23

[Install]
WantedBy=multi-user.target

installed: /usr/local/bin/cpolar
installed link: /usr/bin/cpolar
installed: /usr/local/etc/cpolar/cpolar.yml
installed: /var/log/cpolar/
installed: /var/log/cpolar/access.log
installed: /var/log/cpolar/error.log
installed: /etc/systemd/system/cpolar.service
installed: /etc/systemd/system/[email protected]
removed: /tmp/tmp.zNY8gPayfj
info: Cpolar 3.3.12 is installed.
You may need to execute a command to remove dependent software: apt purge curl unzip
Please execute the command: systemctl enable cpolar; systemctl start cpolar

Check the cpolar version information. If it is displayed normally, the installation is successful:

root@rk3399:/data/cpolar# cpolar version
cpolar version 3.3.12

Perform token authentication:

root@rk3399:/data/cpolar# cpolar authtoken Configure the Authtoken obtained in the first step
Authtoken saved to configuration file: /usr/local/etc/cpolar/cpolar.yml

Configure cpolar to start automatically at boot:

root@rk3399:/data/cpolar# systemctl enable cpolar
Created symlink /etc/systemd/system/multi-user.target.wants/cpolar.service → /etc/systemd/system/cpolar.service.

In daemon mode, start cpolar:

root@rk3399:/data/cpolar# systemctl start cpolar

View cpolar daemon process status;

root@rk3399:/data/cpolar# systemctl status cpolar
● cpolar.service - Cpolar Service
     Loaded: loaded (/etc/systemd/system/cpolar.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2023-11-12 21:21:04 CST; 17s ago
       Docs: https://www.cpolar.com/docs
   Main PID: 6768 (cpolar)
      Tasks: 22 (limit: 4569)
     Memory: 18.1M
     CGroup: /system.slice/cpolar.service
             ├─6768 cpolar: master process
             └─6779 cpolar: worker process

Nov 12 21:21:04 rk3399 systemd[1]: Started Cpolar Service.
1.3 Get the public network address of the ssh tunnel

cpolar will install two sample tunnels by default, one is the Website tunnel pointing to the http 8080 port, and the other is ssh Tunnel, pointing to tcp 22 port;

Access: http://192.168.0.102:9200 in PC machine browser, log in to the cpolar web UI management interface; where 192.168 .0.102 is the intranet IP address of my development board.

In Status -> Online Tunnel List, you can get the public address of the ssh tunnel;

1.4 Public network sshremote linux service

By executing the command on the external network device, you can ssh the remote intranet linux service;

ssh ${linux username}@${public network address generated by cpolar} -p ${port number generated by cpolar}

in:

  • linuxThe user name is the user name of the development board;
  • The public network address generated by cpolar: does not include the protocol name and subsequent port number in the public network address column in the above figure;

For example, I run the command here:

[root@test2 ~]# ssh [email protected] -p 14318

Note: Use cpolar for free. The generated public network address is random and will change every 24 hours. If you need to use it for a long time, you can upgrade the package, configure a fixed domain name address, and increase the bandwidth. The price is not high, and it also supports a 21-day money-back guarantee.

Reference articles

[1] cpolarGetting Started

[2] Build a Web site on Ubuntu and publish it to the public network for access

[3] Domestic intranet penetration tools are also excellent. These 10 tools are recommended for those who are looking for them

The knowledge points of the article match the official knowledge files, and you can further learn relevant knowledge. Cloud native entry-level skills treeHomepageOverview 17058 people are learning the system