示例#1
0
 public function addKey(SshPrivateKey $key)
 {
     if (!$this->isRunning()) {
         // No point in trying to add a key to an agent that is not running
         // so abort early
         return false;
     }
     // Save the key to a temporary file
     $tmpKey = tempnam(sys_get_temp_dir(), 'codeaken_sshagent_');
     file_put_contents($tmpKey, $key->getKeyData(SshKey::FORMAT_PKCS8));
     $sshAdd = new Process("ssh-add {$tmpKey}", null, ['SSH_AUTH_SOCK' => $this->getSocket()], $key->getPassword() . "\n");
     $sshAdd->setPty(true);
     $sshAdd->run();
     if (!$sshAdd->isSuccessful()) {
         unlink($tmpKey);
         return false;
     }
     unlink($tmpKey);
     return true;
 }