python - 通过 ssh 隧道远程运行 ipython notebook

标签 python linux ssh

我想知道我是否可以通过 ssh 远程使用 ipython notebook 两次。 场景是:机器 B 是我要运行 ipython notebook 的机器。但是,我只允许先通过另一台服务器(机器A)访问机器B。 有远程使用ipython notebook的教程,但是都没有提到我遇到的情况。

提前致谢!

最佳答案

假设您指的是 ssh 隧道,并且 ipython notebook 在计算机 B 上的端口 1234 上提供服务:

如果机器 A 可以通过任何端口访问机器 B,您可以设置机器 A 通过 SSH 将远程端口转发给您:

ssh -L 9999:machineB.com:1234 -N machineA.com

这是说

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

但是,如果机器 A 只能通过 ssh 访问机器 B,那么您将需要创建两个隧道。一个从您的客户端 PC 到 machineA,另一个从 machineA 到 machineB。为此,这两个隧道连接到 machineA 上的本地端口而不是远程端口:

ssh -L 9999:localhost:8888 machineA.com ssh -L 8888:localhost:1234 -N machineB.com

这是说

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).

现在,在后台运行该命令后,连接到本地 PC 端口 9999。第一个 ssh 隧道会将请求转发到连接到 localhost:8888 的 machineA,然后第二个 ssh 隧道会将其转发到 machineB,其中它连接到 localhost:1234。

请注意,machineA 需要能够自动连接到 machineB(使用公钥/私钥身份验证)才能在单个命令中工作。

这是一篇很好地解释 ssh 隧道的帖子 https://superuser.com/questions/96489/ssh-tunnel-via-multiple-hops

关于python - 通过 ssh 隧道远程运行 ipython notebook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22518489/

相关文章:

arrays - 用ssh迭代数组

bash - 通过 SSH 执行存储在文件中的 Bash 脚本

python - 使用主管 (Linux) 在关机期间保持程序最后运行

python - TensorFlow 异常退出,代码为 137

php - 从 php 或 python 调用时 Bash 脚本挂起

c - 有没有办法将 Linux 管道设置为非缓冲或行缓冲?

linux - 如何在使用 SVN :SSH method 时制作 SVN 提交后 Hook

python - 将一个列表中随机选择的元素插入另一个列表

python - 使用 pysandbox 限制功能 (RF)

Linux Shell 脚本 : extract values from string in specified manner