~smoser/ubuntu/quantal/cloud-init/sru

« back to all changes in this revision

Viewing changes to cloudinit/CloudConfig/cc_ssh.py

  • Committer: Scott Moser
  • Date: 2011-01-26 22:16:53 UTC
  • mto: This revision was merged to the branch mainline in revision 59.
  • Revision ID: smoser@ubuntu.com-20110126221653-31nkvnsunkt9zdpo
Tags: upstream-0.6.0
ImportĀ upstreamĀ versionĀ 0.6.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
        for key,val in cfg["ssh_keys"].items():
39
39
            if key2file.has_key(key):
40
40
                util.write_file(key2file[key][0],val,key2file[key][1])
 
41
 
 
42
        priv2pub = { 'rsa_private':'rsa_public', 'dsa_private':'dsa_public' }
 
43
        cmd = 'o=$(ssh-keygen -yf "%s") && echo "$o" root@localhost > "%s"'
 
44
        for priv,pub in priv2pub.iteritems():
 
45
            if pub in cfg['ssh_keys'] or not priv in cfg['ssh_keys']: continue
 
46
            pair=(key2file[priv][0], key2file[pub][0])
 
47
            subprocess.call(('sh', '-xc', cmd % pair))
 
48
            log.debug("generated %s from %s" % pair)
41
49
    else:
42
50
        # if not, generate them
43
51
        genkeys ='ssh-keygen -f /etc/ssh/ssh_host_rsa_key -t rsa -N ""; '
60
68
    send_ssh_keys_to_console()
61
69
 
62
70
def send_ssh_keys_to_console():
63
 
    send_keys_sh = """
64
 
    {
65
 
    echo
66
 
    echo "#############################################################"
67
 
    echo "-----BEGIN SSH HOST KEY FINGERPRINTS-----"
68
 
    ssh-keygen -l -f /etc/ssh/ssh_host_rsa_key.pub
69
 
    ssh-keygen -l -f /etc/ssh/ssh_host_dsa_key.pub
70
 
    echo "-----END SSH HOST KEY FINGERPRINTS-----"
71
 
    echo "#############################################################"
72
 
    } | logger -p user.info -s -t "ec2"
73
 
    """
74
 
    subprocess.call(('sh', '-c', send_keys_sh))
 
71
    subprocess.call(('/usr/lib/cloud-init/write-ssh-key-fingerprints',))
75
72
 
76
73
def apply_credentials(keys, user, disable_root):
77
74
    keys = set(keys)
79
76
        setup_user_keys(keys, user, '')
80
77
 
81
78
    if disable_root:
82
 
        key_prefix = 'command="echo \'Please login as the %s user rather than root user.\';echo;sleep 10" ' % user
 
79
        key_prefix = 'command="echo \'Please login as the user \\\"%s\\\" rather than the user \\\"root\\\".\';echo;sleep 10" ' % user
83
80
    else:
84
81
        key_prefix = ''
85
82