繁体   English   中英

在 Google Cloud Platform 上创建的到 VM 的 SSH 隧道不起作用

[英]SSH tunnel to VM created on Google Cloud Platform doesn't work

我正在尝试通过 SSH 隧道连接到在 Google Cloud Platform 上创建的 VM。 问题不在代码中,因为它适用于在不同平台上创建的其他 VM。 问题是我编写的用于将 jupyter notebook 连接到实例的代码运行了几分钟而没有给我任何错误。

这是我的代码: gcloud compute ssh $NODE --project=$PROJ --zone=$ZONE -- -fN -L $PORT:localhost:$PORT

代码中使用的信息(我使用%%bash魔法命令从 jupyter notebook 运行它)是正确的,我仍然不知道为什么代码需要这么多时间来建立连接(并且它无法通过道路)。 非常感谢

首先,您需要一个计算实例来路由所有流量。 如果您有一个现有实例,您可以使用它,或者从 Google Cloud Platform Console 或从 gcloud 创建一个名为 tunnel 的新计算实例:

gcloud compute instances create --zone us-west1-a tunnel

在您机器上的本地端口(例如 5000)上启动 SSH 隧道,该隧道连接到其 SSH 端口 22 上的 GCE 实例:

gcloud compute ssh --zone us-west1-a tunnel -- -N -p 22 -D localhost:5000

此命令在 macOS、Windows 和 Linux 上开箱即用,并启动可用作 SOCKS 代理的 SSH 隧道。 此命令将一直运行直到终止,这将关闭隧道。 如果您确实希望在后台运行它,请将附加的 -f 标志传递给该命令。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM