/** * 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; }
/** * Adds an authorized publickey * * @param string $algoname The algorithm (e.g: ssh-dss, ssh-rsa) * @param string $blob The blob as binary data * @param Boolean $overwrite Whether to overwrite the key if it already * exist * @param array $attributes An associative array of attributes to assign * to the publickey. To mark an attribute as * mandatory, precede its name with an asterisk. * If the server is unable to support an * attribute marked mandatory, it will abort * the add process. * * @return Boolean TRUE on success, or FALSE on failure */ public function add($algoname, $blob, $overwrite = false, array $attributes = array()) { return ssh2_publickey_add($this->getResource(), $algoname, $blob, $overwrite, $attributes); }