Skip to content

Commit 95f9873

Browse files
committed
Ignore SSH host key warning during checks
1 parent c4d29ec commit 95f9873

1 file changed

Lines changed: 28 additions & 3 deletions

File tree

check-workstation-vm.ps1

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,15 +346,40 @@ if ([bool]$cfg.sshEnabled) {
346346
if (-not $ssh) { throw "ssh.exe was not found on the host." }
347347

348348
$ok = $false
349+
$lastSshOutput = ""
349350
foreach ($ip in $ips) {
350-
& $ssh.Source -i $key -o BatchMode=yes -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=NUL -o ConnectTimeout=10 "$($cfg.user)@$ip" "echo hello" 2>$null | Out-Null
351-
if ($LASTEXITCODE -eq 0) {
351+
$sshArgs = @(
352+
"-i", $key,
353+
"-o", "BatchMode=yes",
354+
"-o", "IdentitiesOnly=yes",
355+
"-o", "StrictHostKeyChecking=no",
356+
"-o", "UserKnownHostsFile=NUL",
357+
"-o", "LogLevel=ERROR",
358+
"-o", "ConnectTimeout=10",
359+
"$($cfg.user)@$ip",
360+
"echo hello"
361+
)
362+
$oldErrorActionPreference = $ErrorActionPreference
363+
try {
364+
$ErrorActionPreference = "Continue"
365+
$sshOutput = @(& $ssh.Source @sshArgs 2>&1)
366+
$exitCode = $LASTEXITCODE
367+
} finally {
368+
$ErrorActionPreference = $oldErrorActionPreference
369+
}
370+
if ($exitCode -eq 0) {
352371
Write-Host "SSH ready: $($cfg.user)@$ip"
353372
$ok = $true
354373
break
355374
}
375+
$lastSshOutput = ($sshOutput | ForEach-Object { [string]$_ }) -join "`n"
376+
}
377+
if (-not $ok) {
378+
if (-not [string]::IsNullOrWhiteSpace($lastSshOutput)) {
379+
throw "SSH key login failed. Last ssh output: $lastSshOutput"
380+
}
381+
throw "SSH key login failed."
356382
}
357-
if (-not $ok) { throw "SSH key login failed." }
358383
}
359384

360385
if ([bool]$gpu.enabled) {

0 commit comments

Comments
 (0)