diff options
author | Tiago Gomes <tiago.gomes@codethink.co.uk> | 2013-05-09 14:55:35 +0000 |
---|---|---|
committer | Tiago Gomes <tiago.gomes@codethink.co.uk> | 2013-05-09 14:55:35 +0000 |
commit | cf1cdf88718dda1ca2c98469a649bae168d4793f (patch) | |
tree | 7f6c7816f90da194850626d2833e01116afaea63 /morphlib/exts | |
parent | be72eb1771b0d83bf3a48ac2e59255dc8644e665 (diff) | |
download | morph-cf1cdf88718dda1ca2c98469a649bae168d4793f.tar.gz |
Allow to add public ssh keys to known hosts file
Diffstat (limited to 'morphlib/exts')
-rwxr-xr-x | morphlib/exts/ssh.configure | 15 |
1 files changed, 15 insertions, 0 deletions
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 |