Sean Sean - 1 year ago 119
Python Question

run ipython notebook remotely through ssh tunneling

I am wondering if I can use ipython notebook remotely by ssh twice.
The scenario is: Machine B is the machine I want to run ipython notebook. However, I am only allowed to access machine B through another server (machine A) first.
There are tutorials about using ipython notebook remotely, but none of them mentions the situation I've encountered.

Thanks in advance !

Answer Source

Assuming you are referring to ssh tunnelling, and the ipython notebook is servering on port 1234 on machine B:

If machine A can access machine B on any port, you can setup machine A to forward a remote port to you via SSH:

ssh -L -N

This says

ssh to without executing a remote command (-N) and setup machine A to forward requests from client port 9999, over an ssh tunnel, to machine B port 1234

However if machine A can only access machine B via ssh, then you will need to create two tunnels. One from your client PC to machineA, and another from machineA to machineB. To do this, the two tunnels connect to a local port on machineA instead of a remote port:

ssh -L 9999:localhost:8888 ssh -L 8888:localhost:1234 -N

This says

ssh to and setup machine A to forward requests from our client PC port 9999, over an ssh tunnel, to machine A port 8888. Then execute the command "ssh -L 8888:localhost:1234 -N". This command sets up a second tunnel from machineA port 8888 to machineB port 1234 (where iPython is listening).

Now, with that command running in the background, connect to your local PC port 9999. The first ssh tunnel will forward that request to machineA where it connects to localhost:8888, the second ssh tunnel will then forward it to machineB where it connects to localhost:1234.

Note that machineA will need to be able to connect to machineB automatically (using public/private key authentication) for this to work in a single command.

Here is a post that explains ssh tunnelling nicely

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download