Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jupyter notebook SSH tunnel for two step ssh tunnel

I want to access a jupyter notebook via an SSH tunnel and follow this recipe

https://hsaghir.github.io/data_science/jupyter-notebook-on-a-remote-machine-linux/

To sumarize - : 1. Log in remote machine

user@local_host$ ssh user@remote_host

remote_user@remote_host$ jupyter notebook --no-browser --port=8889

2.In a new terminal:

user@local_host$ ssh -N -L localhost:8888:localhost:8889 remote_user@remote_host

3.Then go to a browser and go to

localhost:8888

Now here is my problem: I can access the remote machine only in two steps

ssh -X username@server

ssh -KX my_pc_name

and the jupyter notebook is only installed on my_pc_name.

What do I write for the second step, when I replace the first line of the first step by my longer log in procedure ?

When I plug in remote_user = username and remote_user = my_pc_name, I get an security error from the jupyter notebook asking for a token. The token that I get from step one, running the jupyter notebook will not work.


One solution could be to combine the two ssh log in steps to one.

like image 651
Uwe.Schneider Avatar asked Mar 16 '19 18:03

Uwe.Schneider


People also ask

Can you have multiple ssh tunnels?

Thankfully, the ssh command allows you to specify multiple tunnels through the same server in one command.


1 Answers

It seems 'server' is your gateway server, and that 'my_pc_name' is accessible only from there. Try establishing two connected ssh tunnels like so:

https://medium.com/@sankarshan7/how-to-run-jupyter-notebook-in-server-which-is-at-multi-hop-distance-a02bc8e78314

So I would do this. Open a terminal and run:

ssh -f username@server -L 8888:localhost:8889 -N

This connects your local machine to the jump server and does port forwarding.

Then open a new terminal and run:

ssh username@server
ssh -f my_pc_name -L 8889:localhost:8889 -N -K

This should connect you to the jump server and do port forwarding between jump server and my_pc_name.

Then open another terminal and run:

ssh -X username@server
ssh -KX my_pc_name
jupyter notebook --no-browser --port=8889

This should connect you to my_pc_name and run the jupyter notebook server there.

Finally go to your browser on your local machine and access: localhost:8888

You do have the -X option in your ssh connection string, which indicates X11 windowing (a type of remote desktop for linux). Try dropping it and see if it still works, else you may have to keep it. Also, -K indicates forwarding of Kerberos tickets, which you probably need to allow file access, so I kept it.

You may have to play with a combination of these on your machine to get it working.

like image 166
Kai Aeberli Avatar answered Nov 15 '22 09:11

Kai Aeberli