From a9332126bb097edf0eb0b1f768423002ed1724b1 Mon Sep 17 00:00:00 2001 From: Cyril Brulebois Date: Sat, 20 Jul 2024 09:04:04 +0200 Subject: [PATCH] Work around longstanding bug regarding SSH host keys. The original image leads to repeated failures to start for sshd.service since there are no host keys initially. Make sure the unit in charge of getting those keys generated runs before sshd. The following block gets repeated otherwise: systemd[1]: Starting ssh.service - OpenBSD Secure Shell server... sshd[795]: sshd: no hostkeys available -- exiting. systemd[1]: ssh.service: Control process exited, code=exited, status=1/FAILURE systemd[1]: ssh.service: Failed with result 'exit-code'. systemd[1]: Failed to start ssh.service - OpenBSD Secure Shell server. systemd[1]: ssh.service: Scheduled restart job, restart counter is at 1. systemd[1]: Stopped ssh.service - OpenBSD Secure Shell server. --- raspberrypi/recipes/pi3-pi4.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/raspberrypi/recipes/pi3-pi4.sh b/raspberrypi/recipes/pi3-pi4.sh index 78e4125..ca505b5 100644 --- a/raspberrypi/recipes/pi3-pi4.sh +++ b/raspberrypi/recipes/pi3-pi4.sh @@ -14,6 +14,11 @@ toast_me() { echo "pi:raspberry" | chroot $MNT chpasswd # Force generate SSH host keys if they exist rm -f $MNT/etc/ssh/ssh_host_* + # Work around longstanding bug (ssh fails to start until host keys + # have been generated on the target), until it's fixed upstream: + if ! grep -qs ^Before= $MNT/etc/systemd/system/rpi-generate-ssh-host-keys.service; then + sed '/^Description=/a Before=sshd.service' -i $MNT/etc/systemd/system/rpi-generate-ssh-host-keys.service + fi # Change the hostname echo "127.0.1.1 pirogue.local pirogue" >> $MNT/etc/hosts echo "::1 pirogue.local pirogue" >> $MNT/etc/hosts