我希望通过 SSH 从远程主机建立端口隧道。我希望将其实现为oclif插件;我希望用户体验是这样的:
laptop$ give-jupyter\nhttp://localhost:4040/\nlaptop$ kill-jupyter\nlaptop$\nRun Code Online (Sandbox Code Playgroud)\n...这应该相对简单;我只是*需要维护一个pidfile,对吧?就像是:
\nlaptop$ give-jupyter\nhttp://localhost:4040/\nlaptop$ kill-jupyter\nlaptop$\nRun Code Online (Sandbox Code Playgroud)\n然而,这一切基本上都不是重点。问题是我必须弄清楚这些标志!哦,那好吧; 这有效:
\nimport child_process from \'child_process\';\nconst childProcess = child_process.spawn(\'ssh\', [/* flags */], {detached: true, stdio: \'ignore\'});\nchildProcess.unref();\nwriteToSomePidfile({childProcess.pid);\nRun Code Online (Sandbox Code Playgroud)\n...但是,它还会在远程端打开一个 shell。没问题,man ssh这就是用途-L:
laptop$ ssh machine -L 4040:localhost:4040\nmachine$ \nRun Code Online (Sandbox Code Playgroud)\n这很好,但它现在正在劫持我用户的 shell。好吧,让我们将进程发送到后台:
\nlaptop$ ssh machine -LN 4040:localhost:4040\n\nRun Code Online (Sandbox Code Playgroud)\n后台版本ssh进入竞争状态,外壳结束STDIN,一切都非常糟糕。好吧,man ssh说的就是这个-n:
laptop$ ssh machine -LN 4040:localhost:4040 &\nlaptop$ f\nf: file not found\nlaptop$ fg\n^C\nRun Code Online (Sandbox Code Playgroud)\n...嗯,那太好了:ssh现在立即退出,隧道也是如此。
SSH 提到-f应该启用某种后台模式,但ssh -fnN也没有这样做;ssh仍然立即退出。
如果我不能拥有好的东西,也许我可以用一个即使没有 STDIN 也能永远运行的命令来近似它们。服务器故障提示:
\nlaptop$ ssh machine -nLN 4040:localhost:4040 &\nlaptop$Job 1, \'ssh machine -nNL 40\xe2\x80\xa6\' has ended\nRun Code Online (Sandbox Code Playgroud)\n还是不行?!美好的:
\nlaptop$ ssh machine -nL 4040:localhost:4040 tail -f /dev/null &\nlaptop$\nRun Code Online (Sandbox Code Playgroud)\n这似乎在一个微小过程的低、低成本下工作,远景比我在写这个问题时尝试过的其他迭代更好,主要涉及yes......
然而,有没有一种...不太笨拙的方法来在后台运行 SSH 隧道?加分点:我也需要它在 OSX 笔记本电脑上工作......
\nPra*_*tne 10
我个人会在系统上创建一个文件,使用控制套接字绑定到隧道-S。当然比处理 PID 更容易。
ssh -M -S ~/jupyter-tunnel -o "ExitOnForwardFailure yes" -fN machine -L 4040:localhost:4040
Run Code Online (Sandbox Code Playgroud)
ssh -S ~/jupyter-tunnel -O exit machine
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3460 次 |
| 最近记录: |