-1

I modified the sshd_config but the ssh service became unavailable. How do I reset the config?

Here is the log:

Jul 29 14:10:03 bye sshd[578]: /etc/ssh/sshd_config line 6: Badly formatted port number.
Jul 29 14:10:03 bye systemd[1]: ssh.service: main process exited, code=exited, status=255/n/a
Jul 29 14:10:03 bye systemd[1]: Unit ssh.service entered failed state.
Jul 29 14:10:04 bye systemd[1]: ssh.service holdoff time over, scheduling restart.
Jul 29 14:10:04 bye systemd[1]: Stopping OpenBSD Secure Shell server...
Jul 29 14:10:04 bye systemd[1]: Starting Google Compute Engine VM initialization...
Jul 29 14:10:04 bye systemd[1]: Started Google Compute Engine VM initialization.
Jul 29 14:10:04 bye systemd[1]: Starting OpenBSD Secure Shell server...
Jul 29 14:10:04 bye systemd[1]: Started OpenBSD Secure Shell server.
Jul 29 14:10:04 bye sshd[582]: /etc/ssh/sshd_config line 6: Badly formatted port number.
Jul 29 14:10:04 bye systemd[1]: ssh.service: main process exited, code=exited, status=255/n/a
Jul 29 14:10:04 bye systemd[1]: Unit ssh.service entered failed state.
Jul 29 14:10:04 bye systemd[1]: ssh.service holdoff time over, scheduling restart.
Misha Brukman
  • 12,938
  • 4
  • 61
  • 78

1 Answers1

2

Since you don't have access to your instance and you need to modify the sshd_config file you can either:

  1. Delete the instance keeping the boot disk, attach it to another instance as secondary, modify the sshd_config file, detach the disk and then create a new instance using that disk.

  2. Or you can modify the sshd_config file using the following startup-script:

    #!/bin/bash /bin/sed -i.bak 's/^Port .*/Port 22/g' /etc/ssh/sshd_config

    This startup-script will modify the line that starts with "Port" to "Port 22". Also it will create a backup at /etc/ssh/sshd_config.bak.

    After updating the instance metadata with the startup-script you need to reboot the instance because startup-scripts are executed when the instances boot up. Once you gain access to the instance, remove the script in order to avoid executing it to no avail.

I hope it helps.

Adrián
  • 2,876
  • 17
  • 22