Visual Studio Code

Remote SSH Session to a "burro"

VSCode is becoming quite popular at the IAC and some of you want to use it locally but using a "Remote SSH Session" to use the resources of a remote, more powerful, machine.

If as a remote machine you are using one of the "burros", you have to bear in mind that if you use a standard "Remote SSH" connection, the computing power available will be very small, i.e. just 75% of a single core. While this might be enough if you are just testing or developing some small code, it probably is not enough if your code can make use of several CPUs (either because you have programmed it explicitly that way or because you are using some package with multithreading capabilities, such as numpy).

In order to have as many CPU cores as needed available to Visual Studio Code you can follow these steps:

Warning

In order to get this to work, you need to verify first that you can connect to the "burro" by using public/private keys and not passwords. If you are not sure how to do this, check https://help.ubuntu.com/community/SSH/OpenSSH/Keys or ask us for help.

Note

The following instructions assume that your local machine uses CernIE (which is true for all the IAC "burros" and most of the Linux laptops), but if you are using, for example, a Mac laptop, you won't have access to the scripts in /opt/SIE/VSCode/.... In this case, it is just a matter of copying the scripts from another machine, and modifying the paths accordingly, but get in touch with us if this is confusing at all.

  • In your local machine (only need to do it once) add a new host description to the ~/.ssh/config file:

Host remote-vscode
  HostName localhost
  Port 33333

Then, every time that you want to use VSCode in a "burro" follow these steps:

  • Log in to the "burro" and launch an interactive session with the required resources (10 cores in the example below), and run the script vscode-remote.sh

    $ sinter -n 10
    salloc: Granted job allocation 133226
    salloc: Waiting for resource configuration
    salloc: Nodes diva are ready for job
    
    (sinter) [user@burro ~]$ /opt/SIE/VSCode/extra/vscode-remote.sh
    
    == Starting connection on port: 43226 ==
    
    From your local machine now run:
    
    /opt/SIE/VSCode/extra/vscode-local.sh diva 43226
    
  • In your local machine run the vscode-local.sh script (just need to copy & paste the command line as given in the output of the previous command):

    user@laptop:$ /opt/SIE/VSCode/extra/vscode-local.sh diva 43226
    Starting SSH tunnel: localhost:33333 -> diva:43226
    SSH tunnel established (PID: 1900664)
    Monitoring remote port 43226... (Press Ctrl+C to stop)
    
  • Now, in VSCode, create a Remote connection by pressing "F1" and then selecting "Remote-SSH: Connect to Host" and then choosing remote-vscode

With that, VSCode will use the resources of the interactive session. If the interactive session is finished (either because it reaches its time limit or because you cancel it), the tunnel created in your local machine with the script vscode-local.sh and the VSCode connection will also get closed.

Note

Above you are creating an interactive session, assuming that what you run with VSCode is not computationally intensive. If for any reason you are going to execute a computationally demanding job from within VSCode, then (as always when using Slurm), instead of an interactive session you should use a batch job.