VSCode remote connection

1 VSCode remote connection server

1. Download vscode

        Search vscode on Baidu (note that it is not visual studio) and enter vscode official website to download.

2. Install ssh plug-in

        ​ ​ ​Select the corresponding version according to your operating system to download and install. After the installation is complete, start vscode, select the Extensions tab on the left, search for remote in the input box, and choose to install the Remote-SSH plug-in.

**3. Add server connection configuration **

        After the download is completed, the "Remote Resource Manager" icon will appear in the sidebar. Open the remote resource manager, click Settings in the upper right corner to enter the configuration interface, write the configuration file, and save it.

Host MyName                    # 服务器名称
    HostName 192.168.0.1     # 服务器ip
    User root                 # 登录用户名
    Port 22                 # 端口, 22
    # IdentityFile "C:\Users\****\.ssh\id_rsa"  # 本地密钥路径

4. Configure remote password-free login

  1. Generate key locally
ssh-keygen -t rsa -C [email protected]
  1. Find the local key location, usually in the C:\\user\\username\\.ssh directory

        Note: Hereid_rsa.pub is the public key, which we need to upload to the /home/username/.ssh folder on the server, id_rsa It is a private key and needs to be used locally

  1. After uploading the public key, output the contents of the public key to the authorized_keys folder by appending
cat id_ras.pub >> authorized_keys

        If the authorized_keys file does not exist, it will be created automatically.

  1. If the modification is unsuccessful, you need to obtain permissions
chmod 700 ~/.ssh/
chmod 600 ~/.ssh/authorized_keys
  1. Add local private key path in local .ssh file
Host MyName                    # 服务器名称
    HostName 210.30.97.162     # 服务器ip
    User root                 # 登录用户名
    Port 22                 # 端口, 9022
    IdentityFile "C:\Users\****\.ssh\id_rsa"  # 本地密钥路径

        If the above steps are successful, you will see all the files in the remote server directory in the Files tab:

        At this point, you can perform operations such as adding, deleting, modifying, and checking files just like operating local files!

2 SSH remotely accesses the server Opencv and matplotlib through VSCode and cannot display images directly.

        When connecting to the server via SSH in VSCode, using cv2.imshow or plt.show() cannot display the image.

The solution is as follows:

1. First check the network connection problem with the server

Open cmd locally and use the command ping xxx.xxx.xxx.xxx, where (xxx.xxx.xxx.xxx is the IP address of the server)

        Ping the local terminal from the server in VSCode or MobaXterm

        Use the command ping xxx.xxx.xxx.xxx, where (xxx.xxx.xxx.xxx is the local IP address)

        At this step, the Windows 11 system in the default state cannot ping. This is because the firewall directly blocks it. Go to the system to turn off the firewall and try again until you can ping.

        Steps to turn off the firewall:

        Control Panel Search Defender

        Then turn off the firewall

2. On the server side

Add to the ~/.bashrc file:

export DISPLAY="10.69.164.78:0.0"

        ​​​The content in quotation marks is the local IP address +:0.0.

        Then run source ~/.bashrc in the terminal to take effect.

        ​​​​Install MobaXterm locally,

        ​​​​ Click Settings–>Configurations–>X11, the settings are as follows

        The Display offset is set to 0. If it is set to 1, the corresponding quotation mark in the second step is changed to the local IP address +:1.0, and so on.

        ​​​​X11 remote access is changed to full, which means that all remote access permissions are open.

3. Configure VSCode

        ​​​​​Note: The Remote X11 plug-in needs to be installed both locally and on the server. If you only installed the plugin locally, search for it again and you will see an option like this and the installation is done

        Enter your ssh configuration C:\Users\xxx\.ssh\config and add at the end:

    ForwardX11 yes
    ForwardX11Trusted yes
    ForwardAgent yes

4. With MobaXterm open, run xclock in VSCode, and a clock will be displayed.

5. Opencv display test (MobaXterm needs to be kept open during the test)

Sample code:

import cv2 as cv
 
src = cv.imread("./spoofing_detection-master/figures/general_flowchart_PAD.png")
cv.namedWindow("test",0)
cv.imshow("test",src)
cv.waitKey(0)
cv.destroyAllWindows()

6. Matplotlib display test (MobaXterm needs to be kept open during the test)

Sample code:

import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
ax = plt.axes(projection='3d')
ax.scatter(np.random.rand(10),np.random.rand(10),np.random.rand(10))
plt.show()

reference

Guess you like

Origin blog.csdn.net/xq151750111/article/details/134064878