def install_ssh_key(self): ''' Install ssh keys on a remote server. Raise Exception if any error. ''' app.print_verbose("Install ssh key") self._check_alive() if (self._is_sshkey_installed()): return self._generate_ssh_keys() # Install key on remote host. self.ssh_exec("mkdir -p .ssh;" + "chmod 700 .ssh;" + "touch .ssh/authorized_keys;" + "chmod 640 .ssh/authorized_keys;" + "echo '" + self._get_public_key() + "' >> .ssh/authorized_keys; " + "restorecon -R -v .ssh") # Raise exception if the installation of the cert failed. if (not self._is_sshkey_installed()): raise SettingsError("Failed to install cert on " + self.server)
def _validate_alive(self, ssh_obj, hostname): if (ssh_obj.is_alive()): self._alive[hostname] = "Yes" else: self._alive[hostname] = "No" raise SettingsError(hostname + " is not alive.")