Jupyter notebook SSH tunnel for two step ssh tunnel

♀尐吖头ヾ 提交于 2020-07-09 05:39:05

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/55199987/jupyter-notebook-ssh-tunnel-for-two-step-ssh-tunnel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!