public static function generateKeyPair($comment = 'dogpro') { $rsa = new RSA(); $rsa->setPublicKeyFormat(RSA::PUBLIC_FORMAT_OPENSSH); $rsa->setComment($comment); return $rsa->createKey(); }
protected function createRSA() { $rsa = new RSA(); $rsa->setPublicKeyFormat(RSA::PUBLIC_FORMAT_OPENSSH); $rsa->setComment($this->config['routerboard']['backupuser'] . "@backup"); $key = $rsa->createKey(2048); if (!empty($key)) { // be safe $this->backupExistRSA(); // create id_rsa.pub (public key) $this->fsys->dumpFile($this->config['system']['ssh-dir'] . DIRECTORY_SEPARATOR . 'id_rsa.pub', $key['publickey']); // create id_rsa (private key) $this->fsys->dumpFile($this->config['system']['ssh-dir'] . DIRECTORY_SEPARATOR . 'id_rsa', $key['privatekey']); // set permissions -rw------- $this->fsys->chmod($this->config['system']['ssh-dir'] . DIRECTORY_SEPARATOR . 'id_rsa', 0600); $this->fsys->chmod($this->config['system']['ssh-dir'] . DIRECTORY_SEPARATOR . 'id_rsa.pub', 0600); // backup existing RSA files for sure. $this->backupExistRSA('routerboard-backup'); $this->logger->log("The SSH-RSA public key has been created. Never delete those files! (id_rsa,id_rsa.pub)", $this->logger->setNotice()); return; } throw new Exception(get_class($this) . " can not create the ssh-rsa public key file!"); }
public function getPair() { $installationUuid = $this->name; $publicKeyName = $this->getPublicKeyPath(); $privateKeyName = $this->getPrivateKeyPath(); if (Storage::exists($publicKeyName) === false || Storage::exists($privateKeyName) === false) { $rsa = new RSA(); $rsa->setPublicKeyFormat(RSA::PUBLIC_FORMAT_OPENSSH); $rsa->setComment('*****@*****.**'); $keys = $rsa->createKey(2048); $privateKey = $keys['privatekey']; $publicKey = $keys['publickey']; Storage::disk('local')->put($privateKeyName, $privateKey); Storage::disk('local')->put($publicKeyName, $publicKey); } return ['public' => $publicKeyName, 'private' => $privateKeyName]; /*$sshConnection = ssh2_connect('mycloud.smellynose.com', 22, array('hostkey'=>'ssh-rsa')); $sshSuccess = ssh2_auth_pubkey_file( $sshConnection, 'ahindle', storage_path('app/' . $publicKeyName), storage_path('app/' . $privateKeyName) );*/ }