1. role push function use password and public key completed

This commit is contained in:
yumaojun
2015-11-15 12:38:57 +08:00
parent 83c2704d53
commit 8b94833ea0
12 changed files with 65 additions and 242 deletions

View File

@@ -3,7 +3,7 @@
import random
import os.path
from Crypto.PublicKey import RSA
from paramiko.rsakey import RSAKey
from os import chmod, mkdir
from uuid import uuid4
@@ -49,14 +49,17 @@ def gen_keys():
key_path_dir = os.path.join(KEY_DIR, key_basename)
mkdir(key_path_dir, 0700)
key = RSA.generate(4096)
key = RSAKey.generate(2048)
private_key = os.path.join(key_path_dir, 'id_rsa')
public_key = os.path.join(key_path_dir, 'id_rsa.pub')
with open(private_key, 'w') as content_file:
content_file.write(key.exportKey('PEM'))
with open(public_key, 'w') as content_file:
content_file.write(key.publickey().exportKey('OpenSSH'))
key.write_private_key_file(private_key)
with open(public_key, 'w') as content_file:
for data in [key.get_name(),
" ",
key.get_base64(),
" %s@%s" % ("jumpserver", os.uname()[1])]:
content_file.write(data)
return key_path_dir