/** * {@inheritdoc} */ public function connect() { $serverConfig = $this->getConfiguration(); $configuration = new Ssh\Configuration($serverConfig->getHost(), $serverConfig->getPort()); switch ($serverConfig->getAuthenticationMethod()) { case Configuration::AUTH_BY_PASSWORD: $authentication = new Ssh\Authentication\Password($serverConfig->getUser(), $serverConfig->getPassword()); break; case Configuration::AUTH_BY_CONFIG: $configuration = new Ssh\SshConfigFileConfiguration($serverConfig->getConfigFile(), $serverConfig->getHost(), $serverConfig->getPort()); $authentication = $configuration->getAuthentication($serverConfig->getPassword(), $serverConfig->getUser()); break; case Configuration::AUTH_BY_IDENTITY_FILE: $authentication = new Ssh\Authentication\PublicKeyFile($serverConfig->getUser(), $serverConfig->getPublicKey(), $serverConfig->getPrivateKey(), $serverConfig->getPassPhrase()); break; case Configuration::AUTH_BY_PEM_FILE: throw new \RuntimeException('If you want to use pem file, switch to using PhpSecLib.'); case Configuration::AUTH_BY_AGENT: $authentication = new \Ssh\Authentication\Agent($serverConfig->getUser()); break; default: throw new \RuntimeException('You need to specify authentication method.'); } $this->session = new Ssh\Session($configuration, $authentication); }
protected function establishConnection($configuration, $authentication) { // User has provided an hostname, build a configuration from the default config file path if (is_string($configuration)) { $configuration = new SshConfigFileConfiguration('~/.ssh/config', $configuration); } // Extract authentication info from the config file if ($authentication === null && $configuration instanceof SshConfigFileConfiguration) { $authentication = $configuration->getAuthentication(); } $this->session = new Session($configuration, $authentication); }