fix when ./keys/user/ didn't exist bug

pull/26/head
liuzheng712 2015-11-17 21:06:38 +08:00
parent 37b91c40b6
commit ee7675f7ae
1 changed files with 2 additions and 1 deletions

View File

@ -130,9 +130,10 @@ def gen_ssh_key(username, password='',
生成一个用户ssh密钥对
"""
private_key_file = os.path.join(key_dir, username)
mkdir(private_key_file, username)
if os.path.isfile(private_key_file):
os.unlink(private_key_file)
ret = bash('ssh-keygen -t rsa -f %s -b %s -P "%s"' % (private_key_file, length, password))
ret = bash('echo -e "y\n"|ssh-keygen -t rsa -f %s -b %s -P "%s"' % (private_key_file, length, password))
if authorized_keys:
auth_key_dir = os.path.join(home, username, '.ssh')