ip, $server->ssh_port ?: 22, $this->connectTimeout); $ssh->setTimeout($this->timeout); $this->verifyHostKey($ssh, $server); $login = $this->vault->resolve($server); if (! $ssh->login($login['username'], $login['secret'])) { throw new RuntimeException("SSH-Login auf {$server->name} ({$server->ip}) fehlgeschlagen."); } $this->ssh = $ssh; return $this; } public function exec(string $command): string { return (string) $this->client()->exec($command); } /** * Run a command and return [stdout, exitCode]. * * @return array{0: string, 1: int|false} */ public function run(string $command): array { $out = $this->exec($command); return [$out, $this->client()->getExitStatus()]; } public function disconnect(): void { $this->ssh?->disconnect(); $this->ssh = null; } private function client(): SSH2 { return $this->ssh ?? throw new RuntimeException('Nicht verbunden — connect() zuerst aufrufen.'); } }