From: https://techtalktone.wordpress.com/2017/03/28/running-jupyter-notebooks-on-a-remote-server-via-ssh/
Jupyter generally returns to you a token with the URL for your browser for the first time you login to it. If you get one, store this somewhere for later.
On the remote machine, kill the IPython server with ctrl-c ctrl-c.
Step 1: On your Remote Computer
SSH into your remote server/machine. Open a Jupyter Notebook using the no-browser option (since we don’t need the browser just yet) on the Terminal.sasha@remote $ jupyter notebook --no-browser --port=8887
I’ve changed the port to 8887 just to make it easier to explain the next step.Jupyter generally returns to you a token with the URL for your browser for the first time you login to it. If you get one, store this somewhere for later.
Step 2: On your Local Computer
Start an SSH Tunnel, and connect it to the Jupyter notebook you just started on the server.ssh -N -L localhost:8888:localhost:8887 sasha@remote
-L binds the local_address:port1 to a
remote_address:port2. To be specific, it specifies that the connections
for the socket on the local host are to be forwarded to the remote host.
The socket then listens to the specified bind address.
-N specifies not to execute a remote command. This is useful when forwarding ports.
On your local computer, navigate to localhost:8888. The browser will
probably ask you for a token. Put the token the Remote Computer returned
to you in the earlier step.To close the SSH tunnel
on the local machine,
look for the process and kill it manually:
local_user@local_host$ ps aux | grep localhost:8889
local_user 18418 0.0 0.0 41488 684 ? Ss 17:27 0:00 ssh -N -f -L localhost:8888:localhost:8889 remote_user@remote_host
local_user 18424 0.0 0.0 11572 932 pts/6 S+ 17:27 0:00 grep localhost:8889
local_user@local_host$ kill -15 18418
Alternatively, you can start the tunnel without the -f option. The process will then remain in the foreground and can be killed with ctrl-c.On the remote machine, kill the IPython server with ctrl-c ctrl-c.