SoFunction
Updated on 2024-12-10

Detailed vscode implementation of Python development on remote linux servers

Recently, I needed to train a generative adversarial network model and then develop the interface, and had to do it on a remote linux server with a graphics card, so I took the opportunity to investigate how to use vscode for remote development.

(1) Run the command at the windows command line:ssh-keygenIf you enter all the way, two files will be generated in the C:\Users\username.ssh directory: id_rsa and id_rsa.pub. The former is the private key and the latter is the public key. As shown below:

(2) Copy the contents of the public key file to the .ssh directory within the home directory of the user who needs to log in without confidentiality on the remote linux server, and rename it to authorized_keys. Note: If more than one machine is logged in to linux for this user, or if the authorized_keys file already exists, start a new line and write the contents of the public key. The ~/.ssh directory structure is shown below:

(3) Modify the .ssh directory and authorized_keys permissions in linux.

# chmod 700 .ssh
# chmod 600 authorized_keys

(4) Test whether the configuration is successful or not, if it is successful, you will be able to log in without password in windows system by the following ways:

# ssh user ID@remote serverip

As shown in the figure below, type "Remote Developement" to find the plug-in, and then click "Install" to install it.

Next, you need to fill in the configuration, following the direction of the arrow in the image below:

The above operation will open the configuration file, in the configuration file, the remote server IP, user name, public key file configuration, fill in the good, "ctrl + S" to save. As shown below:

If you need to develop on multiple remote servers, you can configure multiple Hosts in this configuration file, taking care to specify multiple different Host names.

After finishing the above configuration, you can open the remote server in vscode. As shown below, in the configured Host list, the right mouse button can choose to connect to the remote server in the current window, or create a new window to connect to the remote server.

Take New Window to open the remote server as an example, after clicking on it, the interface is as follows:

In this interface, you can choose the system platform, here, we choose "linux". After that, you can choose to open the directory of the system, after opening, the directory tree will be expanded on the left side:

After connecting to the remote server, we need to configure the interpreter for our program. Note that before this step, you must install the Python plugin for vscode. The installation method is as follows, open the plugin search bar, type "Python", select a search result, click "install" to complete the installation:

Next, you can proceed to configure the compiler. Press "ctrl + shift + P" to bring up the following screen and select the first item "Python: Selectt Interpreter".

Next, vscode will show you a list of all the Python environments on the remote server, so click on the one you want:

At this point, all the steps have been completed and you can write a piece of Python code to test it. It is shown below:

You can see that the output paths are all directories on linux, proving that the configuration was successful.

To this article on the details of this vscode remote linux server Python development on the article is introduced to this, more related vscode remote linux server Python development content please search for my previous articles or continue to browse the following related articles I hope that you will support me in the future more!