From 4b40194c86fcb46b25982d3c1bcc7c1129ca48e2 Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Sat, 11 Jul 2015 19:51:55 -0500 Subject: [PATCH] configure: Add function to enable the SSH daemon The `configure.enable_sshd` function enables the SSH daemon in the target system. It generates host keys and sets the daemon to start at boot. This function is called by `configure.configure` if the VM definition contains at least one network interface. --- src/mkvm/configure.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/mkvm/configure.py b/src/mkvm/configure.py index c52cd69..58ee8a5 100644 --- a/src/mkvm/configure.py +++ b/src/mkvm/configure.py @@ -75,6 +75,16 @@ def enable_console_login(mountpoint, driver): f.write(line) +def enable_sshd(mountpoint): + cmd = ['chroot', mountpoint, 'ssh-keygen', '-A'] + output = subprocess.check_output(cmd) + if output: + log.info(output.decode().strip()) + path = os.path.join(mountpoint, 'etc/runlevels/default/sshd') + if not os.path.exists(path): + os.symlink('/etc/init.d/sshd', path) + + def run_custom_script(mountpoint, script): cmd = ['chroot', mountpoint, '/bin/sh'] env = CUSTOM_SCRIPT_ENV.copy() @@ -98,6 +108,8 @@ def configure(vm): set_hostname(vm.mountpoint, vm.fqdn) if vm.console: enable_console_login(vm.mountpoint, vm.console) + if vm.net_ifaces: + enable_sshd(vm.mountpoint) if vm.customize: run_custom_script(vm.mountpoint, vm.customize)