- auth_keys = dot_ssh + '/authorized_keys'
- logger.log("new keys = %s" % auth_keys)
- auth_file = file(auth_keys,"w")
- for key in new_keys:
- auth_file.write(key)
- auth_file.write("\n")
- auth_file.close()
-
- # set permissions properly
+ auth_keys = os.path.join(dot_ssh,'authorized_keys')
+
+ # catenate all keys in string, add newlines just in case (looks like keys already have this, but)
+ auth_keys_contents = '\n'.join(new_keys)+'\n'
+
+ changes = tools.replace_file_with_string(auth_keys,auth_keys_contents)
+ if changes:
+ logger.log("specialaccounts: keys file changed: %s" % auth_keys)
+
+ # always set permissions properly