R S
R S

Reputation: 11879

Debug port forwarding for using Jupyter notebook remotely

I am trying to use Jupyter notebook on a remote computer. The setup is as follows: I have my home laptop, which can ssh to a specific computer on my university's network (e.g., gateway.myuniv.edu). Once I am logged to gateway.myuniv.edu, I can ssh to the computer on which I would like to run the Jupyter notebook server (e.g. cluster.myuniv.edu).

What works: I can run the server on the gateway and connect to it from my laptop using local port forwarding, as follows:

On gateway.myuniv.edu: $ jupyter notebook --no-browser --port 8888

On my laptop: $ ssh -v -N -L 9000:localhost:8888 [email protected]

Then on my laptop's browser, I open the url: http://localhost:9000

What doesn't work: I don't want to run the server on the gateway, since I can't do heavy computations there. I tried to do the following:

On cluster.myuniv.edu: $ jupyter notebook --no-browser --port 8888

On my laptop: $ ssh -v -N -L 9000:cluster.myuniv.edu:8888 [email protected]

Then on my laptop's browser, I open the url: http://localhost:9000. This doesn't work: SSH says that the connection is refused.

I don't understand why this would happen and how to debug this, would be happy for any help. Thanks!

Upvotes: 6

Views: 4067

Answers (2)

user2343996
user2343996

Reputation: 153

You can use gateway.myuniv.edu as a Jump (ssh -J) host.

  1. So start jupyter notebook on your cluster as you normally do: jupyter notebook --no-browser --port 8888

  2. On your local laptop: ssh [email protected] -J [email protected] -L 8888:localhost:8888 -N

Upvotes: 0

Andrew Andrade
Andrew Andrade

Reputation: 2818

The issue is that you are forwarding port :8888 on cluster.myuniv.edu to port :9000 on gateway.myuniv.edu and then forwarding port :8888 on gateway.myuniv.edu to port 9000 on your laptop.

The solution would the following:

On cluster.myuniv.edu: $ jupyter notebook --no-browser --port 8888

On gateway.myuniv.edu: $ ssh -v -N -L 8888:localhost:8888 [email protected]

On laptop: $ ssh -v -N -L 9000:localhost:8888 [email protected]

I would also recommend that you run Jupyter notebook (on the cluster) and the ssh tunneling (on the gateway) using Tmux or Screen so it remains active even if you close terminal

Upvotes: 5

Related Questions