无法在 Google Cloud 中的 Debian VM 上运行启动脚本 - SSH 和串行控制台访问问题

无法在 Google Cloud 中的 Debian VM 上运行启动脚本 - SSH 和串行控制台访问问题

几天来,我一直在努力解决 Compute Engine VM(Debian GNU/Linux 10)上的 SSH 访问问题,sshd_config 文件中的错误导致无法重新启动 SSH 服务:

2024-03-07T19:15:36.885258-03:00 esal-backup-20240307-212226 sshd[560]: /etc/ssh/sshd_config: line 124: Bad configuration option: ServerAliveInterval
2024-03-07T19:15:36.895808-03:00 esal-backup-20240307-212226 sshd[560]: /etc/ssh/sshd_config: terminating, 1 bad configuration options
2024-03-07T19:15:36.949278-03:00 esal-backup-20240307-212226 systemd[1]: ssh.service: Control process exited, code=exited, status=255/EXCEPTION
2024-03-07T19:15:36.949532-03:00 esal-backup-20240307-212226 systemd[1]: ssh.service: Failed with result 'exit-code'.

为了解决这个问题,我尝试创建一个启动脚本:

#!/bin/bash
sudo sed -i '124s/^/#/' /etc/ssh/sshd_config
sudo systemctl restart sshd

但是,当我重置机器时,尽管我尝试了所有我能想到的方法,但脚本根本无法运行。我的第二种方法是在启动脚本中创建一个用户以访问串行控制台:

useradd USER
echo USER:PASSWORD | chpasswd
usermod -aG google-sudoers USER

再次,启动脚本无法执行,用户未创建。该脚本位于“自动化”>“启动脚本”中。我需要做什么才能让此脚本在机器启动时运行?任何指导都将不胜感激。

相关内容