there is chance that /root/.ssh does not exist yet, when we are trying
to add key to authorized_keys.
Signed-off-by: Kefu Chai <kchai@redhat.com>
).run()
logger.info('Adding key to root@localhost\'s authorized_keys...')
+ if not os.path.exists('/root/.ssh'):
+ os.mkdir('/root/.ssh', mode=0o700)
with open('/root/.ssh/authorized_keys', 'a') as f:
os.fchmod(f.fileno(), 0o600) # just in case we created it
f.write(ssh_pub.strip() + '\n')