Search code examples
sshgoogle-cloud-platformgoogle-compute-enginesshd

google cloud restore sshd_config


I have fucked up my /etc/ssh/sshd_config on a google cloud compute engine VM instance. So I can no longer connect via ssh. Is there a way to restore the file and regain ssh access other than starting all over again?

I added the following line to the file. I thought It would set the default folder for testuser to testfolder when the user connects via sftp.

Subsystem sftp internal-sftp -u testuser -l INFO -d /mnt/disks/testfolder

And I commented out the line

Subsystem sftp /usr/lib/openssh/sftp-server

I guess I shouldn't have done that.


Solution

  • You have two ways to modify the file:

    1) Connecting to the VM using the serial console. I believe this will only work if you have setup already a password for your user. Then you will be able to log in and edit the file. Other details can be found here.

    2) Following a similar approach to the one in the section “Inspect an instance without shutting it down”. Which basically would imply:

    • a) Delete the VM but making sure to keep the disk (--keep-disk=all).If you want to go on the safe side, you could also take a snapshot of the disk and make a new disk from it.

      b) Spin a new VM that can normally boot

      c) Attach the failing disk or its copy to this new VM

      d) Mount the attached disk on Linux FS.

      e) Edit the SSH configuration file.

      f) Detach the disk.

      g) Spin a new VM using the modified disk.