Commit a7afca28 by Kálmán Viktor

Merge branch 'cleanupfix' into 'master'

Fix cleanup and .ssh permissions

closes #14
closes #13

See merge request !6
parents c70e6bc5 34d5248f
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from os import mkdir from os import mkdir, remove, chown
from pwd import getpwnam
import platform import platform
from shutil import rmtree, move from shutil import rmtree, move
import subprocess import subprocess
...@@ -147,7 +148,6 @@ class Context(BaseContext): ...@@ -147,7 +148,6 @@ class Context(BaseContext):
@staticmethod @staticmethod
def _save_keys(keys): def _save_keys(keys):
print keys
try: try:
mkdir(SSH_DIR) mkdir(SSH_DIR)
except OSError: except OSError:
...@@ -156,6 +156,10 @@ class Context(BaseContext): ...@@ -156,6 +156,10 @@ class Context(BaseContext):
for key in keys: for key in keys:
f.write(unicode(key) + '\n') f.write(unicode(key) + '\n')
uid = getpwnam("cloud").pw_uid
chown(SSH_DIR, uid, -1)
chown(AUTHORIZED_KEYS, uid, -1)
@staticmethod @staticmethod
def add_keys(keys): def add_keys(keys):
new_keys = Context.get_keys() new_keys = Context.get_keys()
...@@ -185,13 +189,16 @@ class Context(BaseContext): ...@@ -185,13 +189,16 @@ class Context(BaseContext):
@staticmethod @staticmethod
def cleanup(): def cleanup():
filelist = ([ filelist = ([
'/root/.bash_history' '/root/.bash_history', '/home/cloud/.bash_history',
'/home/cloud/.bash_history' ] + glob('/etc/ssh/ssh_host_*'))
'/root/.ssh' dirlist = ('/root/.ssh', '/home/cloud/.ssh')
'/home/cloud/.ssh']
+ glob('/etc/ssh/ssh_host_*')) for d in dirlist:
rmtree(d, ignore_errors=True)
for f in filelist: for f in filelist:
rmtree(f, ignore_errors=True) if exists(f):
remove(f)
subprocess.call(('/usr/bin/ssh-keygen', '-A')) subprocess.call(('/usr/bin/ssh-keygen', '-A'))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment