My desktop at work is a powerful machine I use for exploratory data analysis and other machine learning work-flows.

In this post I will go over how I connect to my work machine and run Jupyter Notebook workloads when I am working remotely.

SSH into remote machine

Step 1 is to ssh into your remote machine and launch Jupyter Notebook to a local port with the --no-browser option.

user@local_machine$ ssh user@remote_machine 
user@remote_machine$ jupyter notebook --no-browser --port=8889

Setting up an SSH tunnel

Step 2 is to set up an SSH tunnel from your local machine to port 8889 on the remote machine where the Jupyter Notebook is being served.

user@local_machine$ ssh -N -L localhost:8888:localhost:8889 user@remote_mahcine

Here is a break down of the ssh options

  • -N Do not execute a remote command. This is useful for just forwarding ports
  • -L local_socket:remote_socket
  • Specifies that connections to the given TCP port or Unix socket on the local (client) host are to be forwarded to the given host and port, or Unix socket, on the remote side. This works by allocating a socket to listen to either a TCP port on the local side, optionally bound to the specified bind_address, or to a Unix socket. Whenever a connection is made to the local port or socket, the connection is forwarded over the secure channel, and a connection is made to either host port hostport, or the Unix socket remote_socket, from the remote machine.

#data-science #jupyter-notebook #ssh #machine-learning #remote-working #deep learning

Connecting to a Jupyter Notebook on a remote Linux machine with an SSH tunnel
2.45 GEEK