Fixing broken /etc/network/interfaces

淺唱寂寞╮ 提交于 2021-02-11 14:47:22

问题


I have an Ubuntu 16.04 VM on Google Compute Engine.

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?


回答1:


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.

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. Open the VM instance details:

GCP Console => Compute Engine => VM instances => instance_name

2. Stop the VM instance

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. Start the VM instance.

5. Once it started, connect to the console:

=> Connect to serial console

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:~#


来源:https://stackoverflow.com/questions/61472091/fixing-broken-etc-network-interfaces

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!