This article covers different ways to connect and work on remote machines (servers) with the help of SSH. It is currently a WIP and only contains tutorials for Linux/MACOS. Expect it to be updated in the near future (or send a complaint to the author). 

SSH + port forwarding + jupyter (linux/mac)

You can send arbitrary network traffic over SSH, including data for a jupyter-based server. When connecting to the remote server, simply add one (or more) "-L" arguments to the SSH command.

SSH with port forwarding
ssh -L 8888:localhost:12345 <username>@<hostname>

This will map 8888 localhost on your local machine to 12345 on the remote machine. Feel free to select any other two pairs of valid port numbers, just make sure that neither is already taken on the local/remote machine.

You can now start a jupyter server on the remote machine that listens to the selected port.

Starting a jupyter server
jupyter lab --port 12345.

If you open your browser on your local machine and navigate to "localhost:8888" you should find the jupyter lab page. Depending on your config, it might ask you for a token to log in. If so, have a look in the terminal window you used to start up the server. It should be visible as part of a URL string.

SSHFS + any editor

SSHFS is a program that allows you to sync a portion of your local filesystem to a portion of a remote file system. First, you must make sure that you have sshfs installed. It should be available from most Linux package managers and can be easily installed on MACOS using homebrew.

Once you have sshfs, create an empty folder on your local machine, e.g. "project". You can then map the local folder to a corresponding folder on the remote machine with:

Mounting with SSHFS
sshfs -o allow_other <username>@<hostname>:/remote/path/to/project /local/path/to/project

You should now be able to browse and edit the contents of the "project" folder on the remote machine from the "project" folder on you local machine. This means that you can open and edit source code in your favorite editor without any further configuration.

Once you're done working, you can unmount the mapped filesystem with:

Unmounting mapped file system
umount /local/path/to/project


# If this doesn't work, try
fusermount -u /local/path/to/project

This should clear the mapping and restore "project" as an empty folder on your local machine.

Sometimes, the mapped folder gets stuck. A typical way for this to happen is if your network connection drops out for some time. A trick that often helps resolve this issue is to kill the "sshfs" process before trying again.

VS Code

The VS Code editor can be used to connect to remote machines through the "Remote Development extension pack". Begin by installing the extension. This can be done by launching the VS Code Quick Open menu (ctrl + P) and entering "ext install ms-vscode-remote.vscode-remote-extensionpack".

Once the extension is installed, you can connect to a remote host. Open the command palette (Ctrl + Shift + P) and select "Remote SSH: Connect to Host" as shown in the screenshot below.

Then enter your username and host address (<username>@<host>) and select "Linux" in the resulting menu.

The status of the connection should be presented at the bottom left. In the example below we are connected to the host "yoda.idi.ntnu.no".

By clicking on that you can have several commands:

Opening files is the same as local projects. Can be done by: File > (Open or Open Workspace).

To disconnect from the server, select "File > Close Remote Connection".