Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

VS Code allows you to work on remote servers from your local machine. 

Prerequisites

Because we need to hop twice (your local machine -> gateway -> dev node), we need an ssh config file. The following is an example config which defines intel18 and k80 dev node. With this file, you can connect dev node from your local machine with 'ssh intel18' or 'ssh k80'.

Code Block
Host gateway
    HostName gateway.hpcc.msu.edu
    User your_net_id

Host intel18
    HostName dev-intel18
    User your_net_id
    ProxyJump gateway

Host k80
    HostName dev-intel16-k80
    User your_net_id
    ProxyJump gateway

Next, we need an extension program for VS Code. https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack

When the extension is installed, press F1, and select 'Remote-SSH: Connect to Host...'

Then select intel18 or k80.

A new VS Code window will pop up. When you are successfully connected, bottom left of the VS Code will show server information such as 'SSH: intel18'.

Now that you are connected, you can run commands and codes from VS Code. When you are connected to the HPC, all files created through VS Code will be saved to the HPC, not on your local machine.

To test the ability to run remote code, let's create a Python file 'hello.py' with VS Code. Click 'New file' and create a file with the following contest to the file:

Code Block
print('hello!')

Now, open a terminal from 'Terminal' menu from VS Code (or by pressing the key sequence CTRL+Shift+`  and run the code.

Code Block
$ python hello.py

The program's output will be displayed.

Once you have connected the server, click the Remote Explorer to see the list of servers. Click the icon to connect to host in a new window. Right click the name to see the option.