Example #1
0
 /**
  * {@inheritDoc}
  */
 public function createResource()
 {
     $resource = ssh2_publickey_init($this->getSessionResource());
     if (!is_resource($resource)) {
         throw new RuntimeException('The initialization of the publickey subsystem failed.');
     }
     $this->resource = $resource;
 }
Example #2
0
 /**
  * Install your public key in a remote machine’s authorized_keys
  *
  * @param string $std_output The standard output of the executed command
  * @param string $std_error  The standard error of the executed command
  * @param array  $options    Additional options for the specified method
  *
  * @throws Net_SSH2_Exception If the public key is not found.
  * 
  * @return mixed The exit code of the executed command or false on error
  */
 public function sshCopyId(&$std_output, &$std_error, $options = array())
 {
     //Check for valid options
     foreach ($options as $key => $value) {
         $this->{$key} = $value;
     }
     if (!is_readable($this->public_identity_file)) {
         throw new Net_SSH2_Exception(Net_SSH2::getMessage(SSH2_PUBLIC_KEY_UNAVAILABLE));
     }
     $exit_code = 255;
     $pub_key = trim(File::readAll($this->public_identity_file), "\n");
     $pub_key_array = explode(' ', $pub_key);
     try {
         $connection = $this->_authenticate($std_output);
         $pkey = ssh2_publickey_init($connection);
         ssh2_publickey_add($pkey, $pub_key_array[0], base64_decode($pub_key_array[1]), false, array('comment' => $pub_key_array[2]));
         $exit_code = 0;
     } catch (Exception $e) {
         $std_output = $e->getMessage();
     }
     return $exit_code;
 }