summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2011-01-26 15:35:07 -0500
committerScott Moser <smoser@ubuntu.com>2011-01-26 15:35:07 -0500
commita23c2340ef5194871240b9358642f8525297ba2a (patch)
tree98f99fdca985e733e7fb57b50444089995cff446
parenta8f7776c67fe9063862db6a15e4fce5efefbdb98 (diff)
downloadvyos-cloud-init-a23c2340ef5194871240b9358642f8525297ba2a.tar.gz
vyos-cloud-init-a23c2340ef5194871240b9358642f8525297ba2a.zip
cc_ssh: if a private key is supplied, do not require public.
given rsa_private_key, rsa_public_key is not needed in the ssh element of cloud-config. instead, it can be generated with ssh-keygen -yf LP: #648905
-rw-r--r--cloudinit/CloudConfig/cc_ssh.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/cloudinit/CloudConfig/cc_ssh.py b/cloudinit/CloudConfig/cc_ssh.py
index 7b9ba5ab..c4603d2b 100644
--- a/cloudinit/CloudConfig/cc_ssh.py
+++ b/cloudinit/CloudConfig/cc_ssh.py
@@ -38,6 +38,14 @@ def handle(name,cfg,cloud,log,args):
for key,val in cfg["ssh_keys"].items():
if key2file.has_key(key):
util.write_file(key2file[key][0],val,key2file[key][1])
+
+ priv2pub = { 'rsa_private':'rsa_public', 'dsa_private':'dsa_public' }
+ cmd = 'o=$(ssh-keygen -yf "%s") && echo "$o" root@localhost > "%s"'
+ for priv,pub in priv2pub.iteritems():
+ if pub in cfg['ssh_keys'] or not priv in cfg['ssh_keys']: continue
+ pair=(key2file[priv][0], key2file[pub][0])
+ subprocess.call(('sh', '-xc', cmd % pair))
+ log.debug("generated %s from %s" % pair)
else:
# if not, generate them
genkeys ='ssh-keygen -f /etc/ssh/ssh_host_rsa_key -t rsa -N ""; '