From 21a681692ac70e77d3ebe1dd2a76b31de1a72d89 Mon Sep 17 00:00:00 2001 From: Serge Schneider Date: Thu, 24 Nov 2016 20:07:05 +0000 Subject: [PATCH] Port regenerate_ssh_host_key to a systemd service --- stage2/01-sys-tweaks/01-run.sh | 2 +- .../files/regenerate_ssh_host_keys | 36 ------------------- .../files/regenerate_ssh_host_keys.service | 11 ++++++ 3 files changed, 12 insertions(+), 37 deletions(-) delete mode 100644 stage2/01-sys-tweaks/files/regenerate_ssh_host_keys create mode 100644 stage2/01-sys-tweaks/files/regenerate_ssh_host_keys.service diff --git a/stage2/01-sys-tweaks/01-run.sh b/stage2/01-sys-tweaks/01-run.sh index 8e2d149..69fa107 100755 --- a/stage2/01-sys-tweaks/01-run.sh +++ b/stage2/01-sys-tweaks/01-run.sh @@ -1,6 +1,6 @@ #!/bin/bash -e -install -m 755 files/regenerate_ssh_host_keys ${ROOTFS_DIR}/etc/init.d/ +install -m 644 files/regenerate_ssh_host_keys.service ${ROOTFS_DIR}/lib/systemd/system/ install -m 755 files/apply_noobs_os_config ${ROOTFS_DIR}/etc/init.d/ install -m 755 files/resize2fs_once ${ROOTFS_DIR}/etc/init.d/ diff --git a/stage2/01-sys-tweaks/files/regenerate_ssh_host_keys b/stage2/01-sys-tweaks/files/regenerate_ssh_host_keys deleted file mode 100644 index 1a9e34d..0000000 --- a/stage2/01-sys-tweaks/files/regenerate_ssh_host_keys +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/sh -### BEGIN INIT INFO -# Provides: regenerate_ssh_host_keys -# Required-Start: -# Required-Stop: -# Default-Start: 2 -# Default-Stop: -# Short-Description: Regenerate ssh host keys -# Description: -### END INIT INFO - -. /lib/lsb/init-functions - -set -e - -case "$1" in - start) - log_daemon_msg "Regenerating ssh host keys" - nohup sh -c "if [ -e /dev/hwrng ]; then - dd if=/dev/hwrng of=/dev/urandom count=1 bs=4096 - fi; \ - yes | ssh-keygen -q -N '' -t dsa -f /etc/ssh/ssh_host_dsa_key && \ - yes | ssh-keygen -q -N '' -t rsa -f /etc/ssh/ssh_host_rsa_key && \ - yes | ssh-keygen -q -N '' -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key && \ - yes | ssh-keygen -q -N '' -t ed25519 -f /etc/ssh/ssh_host_ed25519_key && \ - sync && \ - rm /etc/init.d/regenerate_ssh_host_keys && \ - update-rc.d regenerate_ssh_host_keys remove && \ - printf '\nfinished\n'" > /var/log/regen_ssh_keys.log 2>&1 - log_end_msg $? - ;; - *) - echo "Usage: $0 start" >&2 - exit 3 - ;; -esac diff --git a/stage2/01-sys-tweaks/files/regenerate_ssh_host_keys.service b/stage2/01-sys-tweaks/files/regenerate_ssh_host_keys.service new file mode 100644 index 0000000..a2d1571 --- /dev/null +++ b/stage2/01-sys-tweaks/files/regenerate_ssh_host_keys.service @@ -0,0 +1,11 @@ +[Unit] +Description=Regenerate SSH host keys + +[Service] +Type=oneshot +ExecStartPre=/bin/sh -c "if [ -e /dev/hwrng ]; then dd if=/dev/hwrng of=/dev/urandom count=1 bs=4096; fi" +ExecStart=/usr/bin/ssh-keygen -A +ExecStartPost=/bin/rm /lib/systemd/system/regenerate_ssh_host_keys.service ; /usr/sbin/update-rc.d regenerate_ssh_host_keys remove + +[Install] +WantedBy=multi-user.target