Google Compute Engine-如果禁用ssh端口,则备用登录虚拟机实例 [英] Google Compute Engine - alternative log in to VM instance if ssh port is disabled

查看:81
本文介绍了Google Compute Engine-如果禁用ssh端口,则备用登录虚拟机实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我登录到我的GCE VM实例(Debian)并安装了 ufw 并启用了它。

I logged in to my GCE VM instance (Debian) and installed ufw and enabled it.

但是,我忘记启用端口22。是否有另一种登录方式,以便我可以启用端口22而不必破坏实例?

However, I forgot to enable port 22. Is there another way to log in so that I can enable port 22 without having to destroy the instance?

推荐答案

不,访问实例的唯一方法是通过SSH。

No, the only way to access to the instance is through SSH.

您可以使用如下启动脚本来启用端口22:

You can enable the port 22 using a startup script like the following one:

#!/bin/bash
/usr/sbin/ufw allow 22/tcp

然后,您可以使用以下命令将此启动脚本添加到实例中开发人员控制台,然后将代码粘贴到自定义元数据部分中,或通过以下命令使用Cloud SDK:

Then, you can add this startup script to your instance either using the Developers Console and pasting the code in the custom metadata section or using the cloud SDK with the command:

gcloud compute instances add-metadata <INSTANCE NAME> --metadata-from-file startup-script=<PATH TO SCRIPT> --project <PROJECT ID>

该脚本将在实例每次启动或重新启动时以root用户身份执行,因此您需要重新启动实例,您可以使用以下方法删除脚本:

This script will be executed as root every time the instance boots up or reboots so you'll need to restart your instance and you can remove the script once you have achieved your goal with:

gcloud compute instances remove-metadata <INSTANCE NAME> --keys startup-script --project <PROJECT ID>

您可以在文档

这篇关于Google Compute Engine-如果禁用ssh端口,则备用登录虚拟机实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆