Google Compute Engine ssh:连接到主机 <IP> 端口 22:操作超时

Abd*_*man 2 ssh ufw google-compute-engine google-cloud-platform

我已经在 Google 计算引擎上设置了我的 VM,并通过 Gcloud 使用 SSH 从我的 Mac 连接到它。我已经安装了我的 Django 网站,然后当我运行以下命令时:

sudo ufw enable
Run Code Online (Sandbox Code Playgroud)

执行此命令后,我无法通过 SSH 连接到我的 VM 实例,我需要为我的站点编辑一些文件,但我无法连接到我的实例。

当我运行以下命令时:

gcloud compute --project "GCP_Project" ssh --zone "my_zone" "Instane_Name"
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

ssh: connect to host <my_ip> port 22: Operation timed out
ERROR: (gcloud.compute.ssh) [/usr/bin/ssh] exited with return code [255].
Run Code Online (Sandbox Code Playgroud)

我不知道,我该如何解决这个问题。

提前致谢!

小智 5

当您打开 UFW 时,拒绝任何传入连接。因此,您需要为端口 22 禁用它,然后您将再次通过 SSH 连接到您的机器。为此,您应该编辑您的实例并运行启动脚本

1) 在 GCP Console 中,转到VM 实例页面

2) 选择实例并单击编辑。

3) 找到自定义元数据选项并单击添加项目并键入启动脚本作为键并复制并粘贴命令sudo ufw allow ssh as a value。此命令将为 SSH 启用端口 22。

4)点击保存

5) 点击页面顶部的重置。重新启动实例后,您应该能够再次 SSH。