예제 #1
0
파일: ssh.py 프로젝트: kemani/syco
    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)
예제 #2
0
 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.")