diff options
Diffstat (limited to 'lib/sunhpc/modules/kickstart/10-hostauth.py')
-rw-r--r-- | lib/sunhpc/modules/kickstart/10-hostauth.py | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/lib/sunhpc/modules/kickstart/10-hostauth.py b/lib/sunhpc/modules/kickstart/10-hostauth.py new file mode 100644 index 0000000..4ffdbc4 --- /dev/null +++ b/lib/sunhpc/modules/kickstart/10-hostauth.py @@ -0,0 +1,62 @@ +#coding:utf-8 +import textwrap +class Modules(object): + """ + Configure sshd, authorized, rsa and so on. + """ + def __init__(self, command): + self.cmd = command + + @property + def __help__(self): + info = """ + #============================================================== + # %s + # + # module_path: %s + # module_name: %s + #============================================================== + """ % (self.__doc__.strip(), self.__module__.strip(), self.__repr__()) + return info + + def run(self, args): + + text = '' + # get root's public keys + public = '/etc/ssh/authorized_keys/id_rsa.pub' + try: + with open(public, 'r') as f: + for key in f.readlines(): + if len(key) > 0: + text = key[:-1] + except: + pass + + content = [] + content.append(self.__help__) + + parts = """ + [ ! -e /root/.ssh ] && mkdir -p /root/.ssh + chmod -R 700 /root/.ssh + + cat > /root/.ssh/authorized_keys << 'EOF' + %s + EOF + chmod 600 /root/.ssh/authorized_keys + + ifconfig virbr0 down + brctl delbr virbr0 + systemctl disable libvirtd.service + + sed -i 's/#UseDNS yes/UseDNS no/' /etc/ssh/sshd_config + + systemctl set-default multi-user.target + + systemctl enable autofs + """ % (text) + + content.append(parts) + self.cmd.ks.addPost(content) + + def __repr__(self): + return "kickstart-secret" |