diff --git a/src/Service/SshConfig.php b/src/Service/SshConfig.php index 3b1f60aa9..6cef2a074 100644 --- a/src/Service/SshConfig.php +++ b/src/Service/SshConfig.php @@ -71,35 +71,39 @@ public function configureSessionSsh() $lines[] = ''; } + + $hostBlock = ''; if ($domainWildcards) { - $lines[] = 'Host ' . implode(' ', $domainWildcards); + $hostBlock = 'Host ' . implode(' ', $domainWildcards); } $sessionIdentityFile = $this->sshKey->selectIdentity(); if ($sessionIdentityFile !== null) { + $lines[] = $hostBlock; $lines[] = '# This SSH key was detected as corresponding to the session:'; $lines[] = sprintf('IdentityFile %s', $this->formatFilePath($sessionIdentityFile)); $lines[] = ''; } - $sessionSpecificFilename = $this->getSessionSshDir() . DIRECTORY_SEPARATOR . 'config'; - $includerFilename = $this->getCliSshDir() . DIRECTORY_SEPARATOR . 'session.config'; - if (empty($lines)) { - if (\file_exists($includerFilename) || \file_exists($sessionSpecificFilename)) { - $this->fs->remove([$includerFilename, $sessionSpecificFilename]); - } - return false; - } - // Add default files if there is no preferred session identity file. if ($sessionIdentityFile === null && ($defaultFiles = $this->getUserDefaultSshIdentityFiles())) { $lines[] = '# Include SSH "default" identity files:'; foreach ($defaultFiles as $identityFile) { + $lines[] = $hostBlock; $lines[] = sprintf('IdentityFile %s', $this->formatFilePath($identityFile)); } $lines[] = ''; } + $sessionSpecificFilename = $this->getSessionSshDir() . DIRECTORY_SEPARATOR . 'config'; + $includerFilename = $this->getCliSshDir() . DIRECTORY_SEPARATOR . 'session.config'; + if (empty($lines)) { + if (\file_exists($includerFilename) || \file_exists($sessionSpecificFilename)) { + $this->fs->remove([$includerFilename, $sessionSpecificFilename]); + } + return false; + } + $this->writeSshIncludeFile($sessionSpecificFilename, $lines); $includerLines = [