Jupyter and VScode Remote on a server behind a gateway

The goal is to be able to work on the remote linux server, which sits behind an ssh gateway or proxy, using GUI apps running natively on the local windows machine.

The first step is to set up the tunnels in PuTTY:

Now you should be able to directly ssh onto the remote server:

$ ssh -p 10022 remote_username@localhost

I find it helpful to configure the connection in the .ssh/config file:

Host my_tunnel
    HostName localhost
    Port 10022
    User remote_username
    IdentityFile ~/.ssh/id_rsa

Now you can simply do $ ssh my_tunnel.

With the configuration stored in the .ssh/config file you can also use the Remote-SSH feature of VScode. However, I found that in order for that to work I need two files. .ssh/config is used by the regular ssh client, which requires it to have permissions only to my Windows user (and not SYSTEM and Administrators). Then I have a second .ssh/config_vscode, which I told VScode to use, as it requires that SYSTEM and Administrators have access to it (as is by default on Windows).

To run jupyter first install it on the remote server. I like to use conda for that. I create a dedicated environment for jupyter, activate it and install the basic packages:

$ conda create --name jupyter
$ conda activate jupyter
$ conda install jupyterlab numpy scipy matplotlib

Then I run command on the remote server that starts a deamon screen session in which jupyter runs.

$ screen -dmS jupyter bash -lc "conda activate jupyter; jupyter lab --ip='*' --no-browser"

By default jupyter will only allow connections from localhost, hence the --ip option. You can always check on this session by connecting to it:

$ screen -r jupyter

And then doing ^a^d to detach again. At first you need to do that to check the login token.

Then on your local machine you can open the browser and go to localhost:18888 and you will see the jupyter lab environment running on the remote server. You will need to give the token for security reasons. You can also immediately on the screen configure a permanent password, so that you don't need to copy the token each time you start jupyter new.