简体   繁体   English

用于两步 ssh 隧道的 Jupyter 笔记本 SSH 隧道

[英]Jupyter notebook SSH tunnel for two step ssh tunnel

I want to access a jupyter notebook via an SSH tunnel and follow this recipe我想通过 SSH 隧道访问 jupyter notebook 并按照这个秘籍

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

To sumarize - : 1. Log in remote machine总结 - : 1. 登录远程机器

user@local_host$ ssh user@remote_host

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

2.In a new terminal: 2.在一个新的终端:

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

3.Then go to a browser and go to 3.然后转到浏览器并转到

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.并且 jupyter notebook 只安装在 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.当我插入remote_user = username 和 remote_user = my_pc_name 时,我从 jupyter notebook 收到一个安全错误,要求提供令牌。 The token that I get from step one, running the jupyter notebook will not work.我从第一步获得的令牌,运行 jupyter notebook 将不起作用。


One solution could be to combine the two ssh log in steps to one.一种解决方案是将两个 ssh 登录步骤合二为一。

It seems 'server' is your gateway server, and that 'my_pc_name' is accessible only from there.似乎“服务器”是您的网关服务器,而“my_pc_name”只能从那里访问。 Try establishing two connected ssh tunnels like so:尝试建立两个连接的 ssh 隧道,如下所示:

https://medium.com/@sankarshan7/how-to-run-jupyter-notebook-in-server-which-is-at-multi-hop-distance-a02bc8e78314 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.这应该将您连接到跳转服务器并在跳转服务器和 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.这应该将您连接到 my_pc_name 并在那里运行 jupyter notebook 服务器。

Finally go to your browser on your local machine and access: localhost:8888最后转到本地计算机上的浏览器并访问: localhost:8888

You do have the -X option in your ssh connection string, which indicates X11 windowing (a type of remote desktop for linux).您的 ssh 连接字符串中确实有 -X 选项,它表示 X11 窗口(一种用于 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.此外,-K 表示转发 Kerberos 票证,您可能需要允许文件访问,所以我保留了它。

You may have to play with a combination of these on your machine to get it working.您可能需要在您的机器上组合使用这些功能才能使其正常工作。

Although we have a great answer from Kai, it might confuse somebody;尽管我们从 Kai 那里得到了很好的回答,但它可能会让某些人感到困惑; at least I had some issues.至少我有一些问题。

In order to establish a connection from your server to a local machine for the jupyter notebook/lab, we need to open three terminal windows on the local machine.为了为 jupyter notebook/lab 建立从您的服务器到本地机器的连接,我们需要在本地机器上打开三个终端窗口

Please follow the order.请遵医嘱。

First terminal window:第一个终端窗口:

ssh -f username1@gateway_server -L :7001:localhost:7001 -N -v -v

don't close the first terminal!不要关闭第一个终端!

Second terminal window:第二个终端窗口:

ssh username1@gateway_server
ssh -f username2@working_server -L 7001:localhost:7001 -N -K -v -v

don't close the second terminal!不要关闭第二个终端!

Third terminal window:第三个终端窗口:

ssh -X username1@gateway_server
ssh -KX username2@working_server
jupyter lab --no-browser --port=7001&

After on your local machine, go to a browser: http://localhost:7001/在本地机器上,转到浏览器:http://localhost:7001/

Tested on Mac.在 Mac 上测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SSH隧道通过Python paramiko - SSH Tunnel through Python paramiko 来自Python的SSH隧道连接太慢 - SSH tunnel from Python is too slow to connect Python的SSH隧道自动关闭 - SSH tunnel from Python is closing automatically 使用 Python 脚本执行 ssh 隧道。 错误:“尝试打开 ssh 隧道时无法解析主机名” - Doing ssh tunnel with Python script. Error: “Could not resolve hostname when trying to open ssh tunnel” 在有监督者上运行的Flask应用程序如何打开SSH隧道? - How can a Flask app running on supervisord open an SSH tunnel? subprocess.Popen ssh隧道启动第二个进程,该进程需要用大头针回答提示 - subprocess.Popen ssh tunnel launches 2nd process which requires answering a prompt with a pin 无法使用类对象中的 ssh 隧道建立到远程 mongoDB 服务器的连接 - Cannot establish connection to remote mongoDB server using ssh tunnel in class object 谷歌云:需要 python 3.6,在 ssh 中为 3.6,但在 jupyter 笔记本中仍为 3.5 - google cloud: need python 3.6 and is 3.6 in ssh but still 3.5 in jupyter notebook Python-如何创建代理隧道 - Python - How to create a tunnel of proxies 合并两个if语句的结果-python / jupyter notebook - Combining the results of two if statements - python / jupyter notebook
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM