Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

run ipython notebook remotely through ssh tunneling

Tags:

python

linux

ssh

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 !

like image 972
Sean Avatar asked Mar 19 '14 21:03

Sean


1 Answers

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 9999:machineB.com:1234 -N machineA.com

This says

ssh to machineA.com 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 machineA.com ssh -L 8888:localhost:1234 -N machineB.com

This says

ssh to machineA.com 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 machineB.com". 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 https://superuser.com/questions/96489/ssh-tunnel-via-multiple-hops

like image 67
Peter Gibson Avatar answered Nov 03 '22 21:11

Peter Gibson