From cf1cdf88718dda1ca2c98469a649bae168d4793f Mon Sep 17 00:00:00 2001 From: Tiago Gomes Date: Thu, 9 May 2013 14:55:35 +0000 Subject: Allow to add public ssh keys to known hosts file --- morphlib/exts/ssh.configure | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'morphlib/exts') diff --git a/morphlib/exts/ssh.configure b/morphlib/exts/ssh.configure index 6012f298..7a7e1667 100755 --- a/morphlib/exts/ssh.configure +++ b/morphlib/exts/ssh.configure @@ -24,6 +24,7 @@ import os import sys import shutil import glob +import re import logging import morphlib @@ -63,6 +64,20 @@ class SshConfigurationExtension(cliapp.Application): if authkey: self.check_dir(dest, mode) self.comb_auth_key(authkey, dest) + + # Fills the known_hosts file + key = 'root_known_host_*_key.pub' + src = os.path.join(os.environ['SSH_KEY_DIR'], key) + known_hosts_keys = glob.glob(src) + known_hosts_path = os.path.join(args[0], 'root/.ssh/known_hosts') + known_hosts_file = open(known_hosts_path, "a") + for filename in known_hosts_keys: + hostname = re.search('root_known_host_(.+?)_key.pub', filename).group(1) + known_hosts_file.write(hostname + " ") + f = open(filename, "r") + known_hosts_file.write(f.read()) + f.close() + known_hosts_file.close() else: self.status(msg="No SSH key directory found.") pass -- cgit v1.2.1