From ce68d5b4810e2c8035b21bfb5f742804c104de5a Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Graber?= Date: Tue, 14 Jan 2014 18:11:29 -0500 Subject: [PATCH] debian: Support ssh host keys regeneration MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Graber Acked-by: Serge E. Hallyn --- templates/lxc-debian.in | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/templates/lxc-debian.in b/templates/lxc-debian.in index d6f07b998..f399c0b1e 100644 --- a/templates/lxc-debian.in +++ b/templates/lxc-debian.in @@ -93,6 +93,30 @@ EOF chroot $rootfs /usr/sbin/update-rc.d -f hwclock.sh remove chroot $rootfs /usr/sbin/update-rc.d -f hwclockfirst.sh remove + # generate new SSH keys + if [ -x $rootfs/var/lib/dpkg/info/openssh-server.postinst ]; then + cat > $rootfs/usr/sbin/policy-rc.d << EOF +#!/bin/sh +exit 101 +EOF + chmod +x $rootfs/usr/sbin/policy-rc.d + + if [ -f $rootfs/etc/init/ssh.conf ]; then + mv $rootfs/etc/init/ssh.conf $rootfs/etc/init/ssh.conf.disabled + fi + + rm -f $rootfs/etc/ssh/ssh_host_*key* + + DPKG_MAINTSCRIPT_PACKAGE=openssh DPKG_MAINTSCRIPT_NAME=postinst chroot $rootfs /var/lib/dpkg/info/openssh-server.postinst configure + sed -i "s/root@$(hostname)/root@$hostname/g" $rootfs/etc/ssh/ssh_host_*.pub + + if [ -f "$rootfs/etc/init/ssh.conf.disabled" ]; then + mv $rootfs/etc/init/ssh.conf.disabled $rootfs/etc/init/ssh.conf + fi + + rm -f $rootfs/usr/sbin/policy-rc.d + fi + # set initial timezone as on host if [ -f /etc/timezone ]; then cat /etc/timezone > $rootfs/etc/timezone -- 2.39.5