修复损坏的/etc/network/interfaces [英] Fixing broken /etc/network/interfaces
问题描述
我在Google Compute Engine上有一个Ubuntu 16.04 VM.
I have an Ubuntu 16.04 VM on Google Compute Engine.
我在etc/network/interfaces中添加了一些命令,然后重新启动了vm以对其进行测试.它们显然是不正确的,而且我无法再通过ssh进入我的虚拟机.有没有一种方法可以在不使用ssh的情况下编辑/etc/network/interfaces文件来恢复虚拟机?
I was adding some commands to etc/network/interfaces, and restarted the vm to test them out. They were apparently incorrect, and I can no longer ssh into my vm. Is there a way I can edit the /etc/network/interfaces file without ssh to recover my vm?
推荐答案
This answer is based on an article Resolving getting locked out of a Compute Engine. Minor corrections were made and the solution was checked for the Debian 9 image.
与裸机一样,如果您可以物理访问它,就有机会获得对操作系统的访问权限.GCE VM也是如此:由于您有权访问VM配置,因此您可以进入内部.
As in the case of bare metal, if you have physical access to it, you have a chance to gain access to the operating system. The same goes for GCE VMs: since you have access to the VM configuration, you can get inside.
1..打开VM实例详细信息:
1. Open the VM instance details:
GCP Console => Compute Engine => VM instances => instance_name
2..停止VM实例
3..启用对串行控制台的访问并添加启动脚本,以创建临时用户:
3. Enable access to the Serial Console and add a startup script so that create a temporary user:
=> Edit =>
Enable connecting to serial ports = True
Custom metadata
Key = startup-script
Value =
useradd --groups "google-sudoers" user3
echo "user3:password" | chpasswd
=> Save
4..启动VM实例.
5..启动后,连接到控制台:
5. Once it started, connect to the console:
=> Connect to serial console
6..按Enter键.出现登录提示.输入用户名( user3
)和密码( password
).您将进入bash外壳.登录的用户是"google-sudoers"组的成员,因此他可以充当root用户:
6. Press Enter. Login prompt appears. Enter username (user3
) and password (password
). You'll get to the bash shell. The logged-in user is a member of the "google-sudoers" group, so he can act as the root user:
$ groups
user3 google-sudoers
$ id
uid=1004(user3) gid=1005(user3) groups=1005(user3),1000(google-sudoers)
$ sudo su -
root@instance-2:~#
这篇关于修复损坏的/etc/network/interfaces的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!