1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Make sure ownership is set correctly for user's new ssh keys

This commit is contained in:
Stephen Fromm 2012-10-30 09:37:23 -07:00
parent f0000a89b0
commit 4619e99443

View file

@ -373,6 +373,7 @@ def ssh_key_gen(module, user, ssh):
if not os.path.exists(ssh_dir): if not os.path.exists(ssh_dir):
try: try:
os.mkdir(ssh_dir, 0700) os.mkdir(ssh_dir, 0700)
os.chown(ssh_dir, info[2], info[3])
except OSError, e: except OSError, e:
return (1, '', 'Failed to create %s: %s' % (ssh_dir, str(e))) return (1, '', 'Failed to create %s: %s' % (ssh_dir, str(e)))
if os.path.exists(ssh_key_file): if os.path.exists(ssh_key_file):
@ -400,6 +401,11 @@ def ssh_key_gen(module, user, ssh):
p = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) p = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(out, err) = p.communicate() (out, err) = p.communicate()
rc = p.returncode rc = p.returncode
if rc == 0:
# If the keys were successfully created, we should be able
# to tweak ownership.
os.chown(ssh_key_file, info[2], info[3])
os.chown('%s.pub' % ssh_key_file, info[2], info[3])
return (rc, out, err) return (rc, out, err)
def ssh_key_fingerprint(module, user, ssh): def ssh_key_fingerprint(module, user, ssh):