VSCode remote debugging Python code environment configuration

overview

Vscode Microsoft's official plug-in Remote Developmentsupports remote access to the server for code debugging. The supported types are Container, SSHand WSL. Here we mainly record the execution method of 本地vscodeadding 远程SSH服务器host access.

deployment method

Environmental requirements

  1. Install vscode locally
  2. The local host and the remote host can be connected through SSH

Deploy password-free login for remote hosts

  1. Use the local DOS command ssh-keygen, press Enter, and C:\User\username\.ssha pair of secret key id_rsaand key will be generated in the directoryid_rsa.pub
    generate key

  2. Add the public key id_rsa.pubto the directory of the remote host /root/.ssh, and rename the file authorized_keys. If the remote host has added password-free login of other machines, that is, the current remote host has authorized_keysa file, copy the content of the public key , and paste it in the file id_rsa.pubof the remote host. authorized_keys.

    insert image description here

  3. Modify file permissions

    chmod 700 /root/.ssh
    chmod 600 /root/.ssh/authorized_keys
    
  4. Test password-free login

    # 使用指令登录,根据实际环境更换user和remote_ip
    ssh user@remote_ip
    

Note: The .ssh directory is stored in the user's home directory of the operating system. For example, for the local operating system, C:\User\Administratorother user names need to be replaced accordingly; for remote Linux hosts, /root/.sshnon-root users are in/home/not_root_user/.ssh

vscode plug-in installation and host connection

  1. install pluginRemote Development
    insert image description here

  2. To configure the remote host connection, click on the left navigation bar Remote Explorerand select the target host type asSSH Targets
    insert image description here

  3. Connect to the host address, click +, fill in the ssh connection command in the address bar on the right ssh [email protected], press Enter to confirm, select the file to save the configuration, it is recommended to selectC:\User\administrator\.ssh/config

    insert image description here insert image description here

  4. Open remote connection window
    insert image description here

  5. The project or project directory can be opened in a new window

    insert image description here

  6. As shown in the example, open the remote Linux host at this time python工程, and at the same time, you can choose远程python解释器环境
    insert image description here

So far, the deployment of the local vscode debugging remote host code environment is completed.

Guess you like

Origin blog.csdn.net/LJX_ahut/article/details/126007063