[Linux] Remotely connect to Ubuntu server code-server on Android tablet for code development

1. Install code-server locally on ubuntu

Prepare a virtual machine, either Ubuntu or centos. Here we take the VMwhere ubuntu system as an example.

Picture 1

Download the code server service, visit the browser:https://github.com/coder/code-server, copy the download link< /span>

Picture 2

Open ubuntu command line download

Picture 3

If you need to enter the login account password for Ubuntu, just enter the password and wait for the installation to complete.

Picture 4

The following information indicates successful installation

Picture 5

Then enter the following command to set the code-server login password

export PASSWORD=”000000”

Picture 6

Check the IP address and use it for LAN access

Picture 7

The code-server service defaults to port number 8080. In order to prevent port 8080 conflict, we modify the code-server port number, enter the following command, and edit the configuration file.

sudo vim ~/.config/code-server/config.yaml

Change 127.0.0.1 to 0.0.0.0, and change port 8080 to your favorite port. In this example, change it to 8077. Save the changes after completing the changes.

image-20230404170252408

After setting the password, start the code-server service and enter the following command:

code-server 

The appearance of address and port number information indicates that the startup is successful.

image-20230404115659896

Then open the browser and access http://192.168.191.129:8077/ through the LAN IP address. Welcone code-server appears to indicate success. Enter the password we set and log in.

image-20230404142030371

2. Install cpolar intranet penetration

Then use cpolar to penetrate the local code-server service so that the android device can be accessed remotely and write code anytime and anywhere. cpolar supports http/https/tcp protocols, does not limit traffic, is simple to operate, and does not require a public IP or router.

cpolar官网:https://www.cpolar.com/

Install cpolar intranet penetration (supports one-click automatic installation script)

  • cpolar installation (for domestic use)
curl -L https://www.cpolar.com/static/downloads/install-release-cpolar.sh | sudo bash
  • Or cpolar short link installation method: (for foreign use)
curl -sL https://git.io/cpolar | sudo bash
  • View version number
cpolar version
  • token authentication

Log in to the cpolar official website backend, click Verify on the left, check your authentication token, and then paste the token in the command line

cpolar authtoken xxxxxxx

20230116114805

  • Add services to the system
sudo systemctl enable cpolar
  • Start cpolar service
sudo systemctl start cpolar
  • Check service status
sudo systemctl status cpolar

Normally displayed asactive means that the service is in a normal online startup state.

3. Create a tunnel mapping local port

After installing cpolar intranet penetration locally on the ubuntu system, access the local 9200 port on the ubuntu browser, or use the LAN IP address to access the 9200 port on an external browser, and open the cpolar web ui interface.

image-20230404142904075

After logging in, click Tunnel Management on the left dashboard - Create Tunnel. Since we configured port 8077 above in code-server, we need to create an http tunnel pointing to port 8077:

  • Tunnel name: It can be customized. Be careful not to duplicate the existing tunnel name.
  • Protocol: http
  • Local address: 8077
  • Port type: random domain name
  • Region: China vip

Click创建

image-20230404143036836

After the creation is successful, we open the online tunnel list, and we can see that the tunnel has just been successfully created, and the corresponding public network address has been generated. Copy the public network address, and then test the remote development and writing code.

image-20230404143350428

4. Android tablet test access

Open the Android browser, any browser, enter the link above to access successfully

image-20230404145124180

5. Fixed domain name and public network address

In cpolar intranet penetration, because the tunnel we just created is a free random temporary tunnel, the public network address it generates will change within 24 hours. For more stable access, we will configure it as a fixed address next. .

You need to upgrade to the basic package or above to support configuring fixed second-level domain names.

Log incpolar official website backend, click 预留 on the left dashboard, find < a i=4>, reserve a second-level subdomain name for the http tunnel. 保留二级子域名

  • Region: Select server region
  • Name: Fill in the second-level subdomain name you want to reserve (can be customized)
  • Description: Notes, which can be customized

image-20230404150209217

This example reserves a second-level subdomain namedcodeservertest. After the subdomain name is successfully reserved, we copy the subdomain name, and then bind its configuration to the tunnel.

image-20230404150252155

Log in to the cpolar web ui management interface, click on the left dashboard 隧道管理——隧道列表, and find the tunnel that needs to be configured with a second-level subdomain name (this In this example, it is the code-server tunnel), click on the right编辑

image-20230404150323396

Modify the tunnel information and configure the second-level subdomain name into the tunnel:

  • Domain Type: Select instead二级子域名
  • Sub Domain: Fill in the second-level subdomain name we just reserved (in this case codeservertest)

After modification is completed, click更新

image-20230404153115506

After the tunnel is updated successfully, click 状态——在线隧道列表 on the left dashboard. You can see that the public network address of the tunnel has been updated to 2 level subdomain name, copy the public network address.

image-20230404153350964

Open the Android browser and enter the fixed http link above to access successfully.

image-20230404154420413

6. Conclusion

Using vscode on Android is mainly to connect to a remote code-server service. Which system the code-server service is installed on will call the environment of the system. For example, if ubuntu is used to install code-server here, then the ubuntu environment will be used, such as It requires go, python, and java development, and the relevant environment needs to be installed in Ubuntu. The folders and projects created are also in Ubuntu. This method actually helps you to connect and use it anytime and anywhere when accessing vscode. And not affected by equipment.

Guess you like

Origin blog.csdn.net/2301_77485708/article/details/134317993