Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Remote-SSH Bug]: Can not connect from macos to windows (powershell error) #10510

Closed
3 tasks done
jurlhardt opened this issue Nov 27, 2024 · 9 comments
Closed
3 tasks done
Assignees
Labels
info-needed Issue requires more information from poster ssh Issue in vscode-remote SSH

Comments

@jurlhardt
Copy link

Is there an existing issue for this bug?

  • I have searched the existing issues

Required Troubleshooting Steps

  • I have followed these troubleshooting steps
  • I have tried both values of the remote.SSH.useLocalServer setting (more info here)

Connect Locally

It connects successfully

->

If I try to connect to the windows host from macos the ssh connection is successfull, but only one line of the script is piped to the powershell session (powershell). I installed the new powershell 7.4 on the windows machine, when I replace 'powershell' with 'pwsh' in the generated ssh command form VsCode I can manually pipe and execute the script successfully. Is there any configuration switch to tell VsCode to use 'pwsh' instead of 'powershell' in the generated ssh command?

VsCode
Version: 1.95.2
Commit: e8653663e8840adaf45af01eab5c627a5af81807
Date: 2024-11-07T11:07:22.054Z
Electron: 32.2.1
ElectronBuildId: 10427718
Chromium: 128.0.6613.186
Node.js: 20.18.0
V8: 12.8.374.38-electron.0
OS: Darwin arm64 23.6.0

Windows
Edition: Windows 10 Enterprise
Version: 22H2
Os build: 19045.5131
Windows Feature Experience Pack 1000.19060.1000.0

PS C:> get-host

Name : ConsoleHost
Version : 5.1.19041.5129
InstanceId : 2fd726eb-8ce9-44f5-9613-f5821bae4237
UI : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture : de-DE
CurrentUICulture : de-DE
PrivateData : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled : True
IsRunspacePushed : False
Runspace : System.Management.Automation.Runspaces.LocalRunspace

Expected Behavior

No response

Steps To Reproduce

No response

Remote-SSH Log

Remote-SSH Log

[08:16:07.542] Log Level: 2
[08:16:07.553] SSH Resolver called for "ssh-remote+10.252.59.58", attempt 1
[08:16:07.554] remote.SSH.useLocalServer = false
[08:16:07.554] remote.SSH.useExecServer = false
[08:16:07.554] remote.SSH.showLoginTerminal = true
[08:16:07.554] remote.SSH.remotePlatform = {"bacdev2":"linux","10.252.59.58":"windows"}
[08:16:07.554] remote.SSH.path = undefined
[08:16:07.554] remote.SSH.configFile = undefined
[08:16:07.554] remote.SSH.useFlock = true
[08:16:07.554] remote.SSH.lockfilesInTmp = false
[08:16:07.554] remote.SSH.localServerDownload = auto
[08:16:07.554] remote.SSH.remoteServerListenOnSocket = false
[08:16:07.554] remote.SSH.defaultExtensions = []
[08:16:07.554] remote.SSH.loglevel = 2
[08:16:07.554] remote.SSH.enableDynamicForwarding = true
[08:16:07.554] remote.SSH.enableRemoteCommand = false
[08:16:07.554] remote.SSH.serverPickPortsFromRange = {}
[08:16:07.554] remote.SSH.serverInstallPath = {}
[08:16:07.555] remote.SSH.permitPtyAllocation = false
[08:16:07.555] remote.SSH.preferredLocalPortRange = undefined
[08:16:07.555] remote.SSH.useCurlAndWgetConfigurationFiles = false
[08:16:07.559] VS Code version: 1.95.2
[08:16:07.559] Remote-SSH version: [email protected]
[08:16:07.559] darwin arm64
[08:16:07.572] SSH Resolver called for host: 10.252.59.58
[08:16:07.572] Setting up SSH remote "10.252.59.58"
[08:16:07.587] Using commit id "e8653663e8840adaf45af01eab5c627a5af81807" and quality "stable" for server
[08:16:07.595] Script variables:
 {
  "InstallExitCode.24": "AlreadyInProgress",
  "InstallExitCode.25": "ServerDownloadFailed",
  "InstallExitCode.26": "NoDownloaderAvailable",
  "InstallExitCode.27": "UnsupportedArch",
  "InstallExitCode.28": "StatusCheckFailed",
  "InstallExitCode.29": "NeedInsidersArch",
  "InstallExitCode.30": "NoDownloaderAvailableForStatusCheck",
  "InstallExitCode.31": "ServerTransferFailed",
  "InstallExitCode.32": "ServerFailedToStart",
  "InstallExitCode.33": "NeedInsidersWindows",
  "InstallExitCode.34": "CreateInstallDirFailed",
  "InstallExitCode.35": "UnsupportedPlatform",
  "InstallExitCode.36": "ServerTerminatedCVE20201416",
  "InstallExitCode.37": "UnpackFailed",
  "InstallExitCode.38": "ChangeDirFailed",
  "InstallExitCode.AlreadyInProgress": "24",
  "InstallExitCode.ServerDownloadFailed": "25",
  "InstallExitCode.NoDownloaderAvailable": "26",
  "InstallExitCode.NoDownloaderAvailableForStatusCheck": "30",
  "InstallExitCode.UnsupportedArch": "27",
  "InstallExitCode.StatusCheckFailed": "28",
  "InstallExitCode.NeedInsidersArch": "29",
  "InstallExitCode.ServerTransferFailed": "31",
  "InstallExitCode.ServerFailedToStart": "32",
  "InstallExitCode.NeedInsidersWindows": "33",
  "InstallExitCode.CreateInstallDirFailed": "34",
  "InstallExitCode.UnsupportedPlatform": "35",
  "InstallExitCode.ServerTerminatedCVE20201416": "36",
  "InstallExitCode.UnpackFailed": "37",
  "InstallExitCode.ChangeDirFailed": "38",
  "InstallUnpackCode.Success": "success",
  "InstallUnpackCode.Error": "error",
  "InstallUnpackCode.MissingFiles": "missingFiles",
  "uuid": "6ff000401878",
  "startMarker": "6ff000401878: running",
  "commitId": "e8653663e8840adaf45af01eab5c627a5af81807",
  "quality": "stable",
  "token": "a1aaaaaa-11aa-11aa-11a1-aaa1a111a111",
  "vscodeAgentFolder": "$HOME/.vscode-server",
  "allowClientDownload": "1",
  "forceClientDownload": "0",
  "cliNameInArchive": "code",
  "ignoreWgetConfigFlag": " --no-config ",
  "ignoreCurlConfigFlag": " --disable ",
  "wgetTriesSegment": "--tries=1",
  "listenArgs": "--on-host=127.0.0.1 --on-port",
  "getDownloadServerStartTrigger": "6ff000401878:trigger_server_download",
  "getDownloadServerEndTrigger": "6ff000401878:trigger_server_download_end",
  "getProgressDownloading": "6ff000401878%%1%%",
  "getProgressInstalling": "6ff000401878%%2%%"
}
[08:16:07.597] Install and start server if needed
[08:16:07.600] PATH: /Users/user/.rd/bin:/Users/user/jdk-18.0.2.1.jdk/Contents/Home/bin:/Users/user/homebrew/bin:/Users/user/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin:/Library/TeX/texbin:/Applications/VMware Fusion.app/Contents/Public:/Users/user/Library/Application Support/JetBrains/Toolbox/scripts:/Users/user/.local/bin:/Users/user/.local/bin
[08:16:07.600] Checking ssh with "ssh -V"
[08:16:07.618] > OpenSSH_9.7p1, LibreSSL 3.3.6

[08:16:07.623] Remote command length: 6314/8192 characters
[08:16:07.623] Running script with connection command: ssh -T -D 59383 -o ConnectTimeout=15 '10.252.59.58' powershell
[08:16:07.623] Generated SSH command: 'ssh -T -D 59383 -o ConnectTimeout=15 '10.252.59.58' powershell << 'EOSSH'

$uuid="6ff000401878"
"${uuid}: running"
"6ff000401878: pauseLog"
$ProgressPreference='SilentlyContinue'
$n_='e8653663e8840adaf45af01eab5c627a5af81807'
$p=$env:PROCESSOR_ARCHITECTURE
$arch=''
if ($p -eq 'AMD64' -or $p -eq 'IA64') {
$arch='x64'
} elseif ($p -eq 'ARM64') {
$arch='arm64'
}

if ($arch -eq '') {
"Unsupported architecture '$p'."
q 27
}

$o_=(Join-Path (Resolve-Path ~) '.vscode-server')
$log="$o_\.$n_.log"
$ai_="$o_\.$n_.token"
$sDir="$o_\bin\$n_"
$sFile="$o_\bin\$n_\bin\code-server.cmd"
$p_='stable'
$q_="--telemetry-level all"
$exts=""
$g_=$True
$h_=$False
$global:r_ = $False
$global:s_ = ''
$global:j_ = ''
$global:k_ = ''
$global:l_ = ''
$global:m_ = ''
$global:aj_ = ''
function ao_ {
"listeningOn==$port=="
"osReleaseId==windows=="
"osVersion==$ah_=="
"arch==$arch=="
"platform==windows=="
"unpackResult==$s_=="
"didLocalDownload==$r_=="
"downloadTime==$j_=="
"installTime==$k_=="
"extInstallTime==$l_=="
"serverStartTime==$m_=="
}

function i_ {
return [system.diagnostics.stopwatch]::StartNew();
}

function q($code) {
"${uuid}: start"
"exitCode==$code=="
ao_
"${uuid}: end"
}

function a_ {
$t_=$PID
while ($True) {
$u_=(gcim win32_process | ? processid -eq $t_).parentprocessid
if (!$u_) {
"no sshd parent proc"
exit 0
}

if ((gps -Id $u_).Name -eq 'sshd') {
return $u_
}

$t_=$u_
}

}

function b_ {
if ($v_) {
if (!(gps -Id $v_)) {
"server died, exit"
exit 0
}

} else {
if (!(gps -Id $sshdPID)) {
"sshd parent died, exit"
exit 0
}

}

}

function GetArtifactName {
$w_=""
"server-win32-$arch" + $w_
}

function c_ {
$s=i_
"Downloading server $arch"
"${uuid}%%1%%"
$y_=GetArtifactName
$splat=@{
Uri="https://update.code.visualstudio.com/commit:$n_/$y_/$p_"
TimeoutSec=20
OutFile="vscode-server.zip"
UseBasicParsing=$True
}

[Net.ServicePointManager]::SecurityProtocol = 'Tls12'
irm @splat
$s.Stop()
$global:j_ = $s.ElapsedMilliseconds
}

function d_ {
$global:s_='success'
$s=i_
try {
$z_=[System.IO.Path]::GetRandomFileName()
$aa_="$env:TEMP\$z_"
"Expanding server into $aa_"
"${uuid}%%2%%"
Expand-Archive "vscode-server.zip" -DestinationPath "$aa_"
cp -Recurse "$aa_\vscode-*\*" -Destination .
del -Recurse $aa_
$s.Stop()
$global:k_ = $s.ElapsedMilliseconds
} catch {
$global:s_='error'
"Failed to unzip server. - $($_.ToString())"
f_ 37
d_
}

if(!(Test-Path "$sFile")) {
$global:s_='missingFiles'
"Downloaded server is incomplete."
f_ 37
d_
}

}

function ak_ {
$aq_=[System.Security.Principal.WindowsIdentity]::GetCurrent().Name
$global:aj_ = "b96f8a12-9125-4368-b6b7-8d3864be874d"
ni -it f $ai_ -Force
icacls $ai_ /reset /Q
icacls $ai_ /setowner "$aq_" /Q
icacls $ai_ /grant "$($aq_):(R,W)" /Q
icacls $ai_ /inheritance:r /Q
[System.IO.File]::WriteAllLines($ai_, $global:aj_)
}

function am_ {
if($False) {
return "--port=0-0"
}

return "--port=0"
}

function al_ {
$s=i_
if(Test-Path $log) {
del $log
}

$escapedServerFile=$sFile -replace ' ', '` '
ak_
$portFlag=am_
$args="--start-server --host=127.0.0.1 --server-data-dir '$o_' --accept-server-license-terms --enable-remote-auto-shutdown $portFlag --connection-token-file '$ai_' $q_ $exts *> '$log'"
$splat=@{
FilePath = "powershell.exe"
WindowStyle = "hidden"
ArgumentList = @(
"-ExecutionPolicy", "Unrestricted", "-NoLogo", "-NoProfile", "-NonInteractive", "-c", "$escapedServerFile $args"
)
PassThru = $True
}

"Starting server: & '$sFile' $args"
$global:v_ = (start @splat).ID
$s.Stop()
$global:m_ = $s.ElapsedMilliseconds
}

function e_ {
$global:r_=$True
"Trigger local server download"
$y_=GetArtifactName
"${uuid}:trigger_server_download"
"artifact==$y_=="
"destFolder==$o_\bin\=="
"destFolder2==$n_\vscode-server.zip=="
"${uuid}:trigger_server_download_end"
"Waiting for client to transfer server archive..."
"Waiting for $sDir\vscode-server.zip.done and vscode-server.zip to exist"
while($True) {
if(Test-Path "$sDir\vscode-server.zip.done") {
if(!(Test-Path "$sDir\vscode-server.zip")) {
"Transfer failed"
q 31
}

"Transfer complete"
del $sDir\vscode-server.zip.done
break
} else {
Start-Sleep -Seconds 3
b_
}

}

}

function f_($code) {
if ($r_) {
"Already attempted local download, failing"
q $code
} elseif($g_) {
e_
} else {
q $code
}

}

function an_ {
if ($exts -ne "") {
$s=i_
& "$sFile" $q_ @exts
$s.Stop()
$global:l_ = $s.ElapsedMilliseconds
}

}

function acquireLock() {
$ac_=(Join-Path "$sDir" "vscode-remote-lock.$n_")
try {
$null=ni $ac_ -it f -ea si
} catch {
"Could not create server lock file. - $($_.ToString())"
return
}

try {
"Acquiring lock on $ac_"
$global:file = [System.io.File]::Open($ac_, 'Open', 'Read', 'None')
} catch {
"Install already in progress... - $($_.ToString())"
q 24
}

}

function printResult() {
"${uuid}: start"
"SSH_AUTH_SOCK==$env:SSH_AUTH_SOCK=="
ao_
"connectionToken==$global:aj_=="
"${uuid}: end"
}

function main() {
$global:sshdPID = a_
if(!(Test-Path $sDir)) {
$m="Could not create server directory"
try {
$null=ni -it d $sDir -f -ea si
} catch {
"$m. - $($_.ToString())"
return
}

if(!(Test-Path $sDir)) {
"$m"
return
}

}

cd $sDir
acquireLock
try {
"Looking for existing server in $sDir"
if(Test-Path "$sFile") {
"Found installed server"
} else {
if ($h_) {
e_
} else {
try { c_ } catch {
"Download failed. - $($_.ToString())"
f_ 25
}

}

d_
}

if(!(Get-Process node -ErrorAction SilentlyContinue | Where-Object Path -Like "$sDir\*")) {
al_
} else {
"Server with $n_ is already running."
an_
if (Test-Path $ai_) {
$global:aj_ = $(cat $ai_)
}

}

$af_=@{
Path = $log
Pattern = "Extension host agent listening on (\d+)"
}

$ae_=@{
Path = $log
Pattern = "!!!! Server terminated due to presence of CVE-2020-1416 !!!!"
}

$ad_=(Get-Date).AddSeconds(4)
$ap_="Server did not start successfully. Full server log at $log >>>"
while ((Get-Date) -lt $ad_) {
if(Test-Path $log) {
$ag_=(sls @af_).Matches.Groups
if($ag_) {
$global:port = $ag_[1].Value
break
}

$failed=(sls @ae_).Matches.Groups
if($failed) {
$ap_
cat $log
"<<< End of server log"
q 36
}

}

sleep -Milliseconds 30
}

if (!$port) {
$ap_
cat $log
"<<< End of server log"
q 32
}

} catch {
"Server failed to start. - $($_.ToString())"
} finally {
$file.Close()
}

try {
$global:ah_ = (gcim Win32_OperatingSystem).Version
} catch {
"Failed to find Windows version - $($_.ToString())"
$global:ah_ = "unknown"
}

printResult
"$pid, watching $sshdPID"
while ($True) {
b_
sleep 30
}

}

"6ff000401878: resumeLog"
main

EOSSH'
[08:16:07.623] Using connect timeout of 17 seconds
[08:16:08.362] > [email protected]'s password: 
[08:16:08.363] Got some output, clearing connection timeout
[08:16:19.601] > 
[08:16:21.707] > Windows PowerShell
> Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten.
> 
> Lernen Sie das neue plattform�bergreifende PowerShell kennen - https://aka.ms/pscore6
> 
> PS C:\Users\user> 
[08:16:21.956] "install" terminal command done
[08:16:21.957] Install terminal quit with output: PS C:\Users\user> 
[08:16:21.957] Received install output: PS C:\Users\user> 
[08:16:21.957] WARN: $PLATFORM is undefined in installation script output.  Errors may be dropped.
[08:16:21.957] Failed to parse remote port from server output
[08:16:21.958] Resolver error: Error: 
	at v.Create (/Users/user/.vscode/extensions/ms-vscode-remote.remote-ssh-0.116.2024111219/out/extension.js:2:575962)
	at t.handleInstallOutput (/Users/user/.vscode/extensions/ms-vscode-remote.remote-ssh-0.116.2024111219/out/extension.js:2:573184)
	at t.tryInstall (/Users/user/.vscode/extensions/ms-vscode-remote.remote-ssh-0.116.2024111219/out/extension.js:2:691577)
	at async /Users/user/.vscode/extensions/ms-vscode-remote.remote-ssh-0.116.2024111219/out/extension.js:2:650540
	at async t.withShowDetailsEvent (/Users/user/.vscode/extensions/ms-vscode-remote.remote-ssh-0.116.2024111219/out/extension.js:2:653784)
	at async x (/Users/user/.vscode/extensions/ms-vscode-remote.remote-ssh-0.116.2024111219/out/extension.js:2:647325)
	at async t.resolve (/Users/user/.vscode/extensions/ms-vscode-remote.remote-ssh-0.116.2024111219/out/extension.js:2:651199)
	at async /Users/user/.vscode/extensions/ms-vscode-remote.remote-ssh-0.116.2024111219/out/extension.js:2:931496
[08:16:21.962] ------




[08:16:22.558] Opening exec server for ssh-remote+10.252.59.58
[08:16:22.569] Initizing new exec server for ssh-remote+10.252.59.58
[08:16:22.570] Using commit id "e8653663e8840adaf45af01eab5c627a5af81807" and quality "stable" for server
[08:16:22.577] Script variables:
 {
  "InstallExitCode.24": "AlreadyInProgress",
  "InstallExitCode.25": "ServerDownloadFailed",
  "InstallExitCode.26": "NoDownloaderAvailable",
  "InstallExitCode.27": "UnsupportedArch",
  "InstallExitCode.28": "StatusCheckFailed",
  "InstallExitCode.29": "NeedInsidersArch",
  "InstallExitCode.30": "NoDownloaderAvailableForStatusCheck",
  "InstallExitCode.31": "ServerTransferFailed",
  "InstallExitCode.32": "ServerFailedToStart",
  "InstallExitCode.33": "NeedInsidersWindows",
  "InstallExitCode.34": "CreateInstallDirFailed",
  "InstallExitCode.35": "UnsupportedPlatform",
  "InstallExitCode.36": "ServerTerminatedCVE20201416",
  "InstallExitCode.37": "UnpackFailed",
  "InstallExitCode.38": "ChangeDirFailed",
  "InstallExitCode.AlreadyInProgress": "24",
  "InstallExitCode.ServerDownloadFailed": "25",
  "InstallExitCode.NoDownloaderAvailable": "26",
  "InstallExitCode.NoDownloaderAvailableForStatusCheck": "30",
  "InstallExitCode.UnsupportedArch": "27",
  "InstallExitCode.StatusCheckFailed": "28",
  "InstallExitCode.NeedInsidersArch": "29",
  "InstallExitCode.ServerTransferFailed": "31",
  "InstallExitCode.ServerFailedToStart": "32",
  "InstallExitCode.NeedInsidersWindows": "33",
  "InstallExitCode.CreateInstallDirFailed": "34",
  "InstallExitCode.UnsupportedPlatform": "35",
  "InstallExitCode.ServerTerminatedCVE20201416": "36",
  "InstallExitCode.UnpackFailed": "37",
  "InstallExitCode.ChangeDirFailed": "38",
  "InstallUnpackCode.Success": "success",
  "InstallUnpackCode.Error": "error",
  "InstallUnpackCode.MissingFiles": "missingFiles",
  "uuid": "7e35ae4aa861",
  "startMarker": "7e35ae4aa861: running",
  "commitId": "e8653663e8840adaf45af01eab5c627a5af81807",
  "quality": "stable",
  "token": "1a1a111a-1111-111a-111a-1a11a1111111",
  "vscodeAgentFolder": "$HOME/.vscode-server",
  "allowClientDownload": "1",
  "forceClientDownload": "0",
  "cliNameInArchive": "code",
  "ignoreWgetConfigFlag": " --no-config ",
  "ignoreCurlConfigFlag": " --disable ",
  "wgetTriesSegment": "--tries=1",
  "listenArgs": "--on-host=127.0.0.1 --on-port",
  "getDownloadServerStartTrigger": "7e35ae4aa861:trigger_server_download",
  "getDownloadServerEndTrigger": "7e35ae4aa861:trigger_server_download_end",
  "getProgressDownloading": "7e35ae4aa861%%1%%",
  "getProgressInstalling": "7e35ae4aa861%%2%%"
}
[08:16:22.578] Install and start server if needed
[08:16:22.582] Remote command length: 4962/8192 characters
[08:16:22.582] Running script with connection command: ssh -T -D 59390 -o ConnectTimeout=15 '10.252.59.58' powershell
[08:16:22.582] Generated SSH command: 'ssh -T -D 59390 -o ConnectTimeout=15 '10.252.59.58' powershell << 'EOSSH'

$uuid="7e35ae4aa861"
"${uuid}: running"
"7e35ae4aa861: pauseLog"
$ProgressPreference='SilentlyContinue'
$r_='e8653663e8840adaf45af01eab5c627a5af81807'
$p=$env:PROCESSOR_ARCHITECTURE
$arch=''
if ($p -eq 'AMD64' -or $p -eq 'IA64') {
$arch='x64'
} elseif ($p -eq 'ARM64') {
$arch='arm64'
}

if ($arch -eq '') {
"Unsupported architecture '$p'."
q 27
}

$s_=(Join-Path (Resolve-Path ~) '.vscode-server')
$cliDataDir=(Join-Path "$s_" 'cli')
$env:VSCODE_AGENT_FOLDER=$s_
$log=New-TemporaryFile
$c_="code"
$d_="$c_.exe"
$e_="$c_-$r_.exe"
$f_="$s_\$e_"
$t_='stable'
$k_=$True
$l_=$False
$global:v_ = $False
$global:w_ = ''
$global:n_ = ''
$global:o_ = ''
$global:p_ = ''
$global:q_ = ''
function ak_ {
"listeningOn==$port=="
"osReleaseId==windows=="
"osVersion==$ai_=="
"arch==$arch=="
"platform==windows=="
"unpackResult==$w_=="
"didLocalDownload==$v_=="
"downloadTime==$n_=="
"installTime==$o_=="
"extInstallTime==$p_=="
"serverStartTime==$q_=="
"execServerToken==0a2f233e-5312-425c-820c-5d80e7794740=="
}

function m_ {
return [system.diagnostics.stopwatch]::StartNew();
}

function q($code) {
"${uuid}: start"
"exitCode==$code=="
ak_
"${uuid}: end"
}

function a_ {
$x_=$PID
while ($True) {
$y_=(gcim win32_process | ? processid -eq $x_).parentprocessid
if (!$y_) {
"no sshd parent proc"
exit 0
}

if ((gps -Id $y_).Name -eq 'sshd') {
return $y_
}

$x_=$y_
}

}

function b_ {
if ($launchedCli1Pid) {
if (!(gps -Id $z_)) {
"server died, exit"
exit 0
}

} else {
if (!(gps -Id $sshdPID)) {
"sshd parent died, exit"
exit 0
}

}

}

function GetArtifactName {
"cli-win32-$arch"
}

function g_ {
$s=m_
"Downloading cli $arch"
"${uuid}%%1%%"
$an=GetArtifactName
$splat=@{
Uri="https://update.code.visualstudio.com/commit:$r_/$an/$t_"
TimeoutSec=20
OutFile="vscode-cli-$r_.zip"
UseBasicParsing=$True
}

[Net.ServicePointManager]::SecurityProtocol = 'Tls12'
irm @splat
$s.Stop()
$global:n_ = $s.ElapsedMilliseconds
}

function h_ {
$global:w_='success'
$s=m_
try {
$ac_=[System.IO.Path]::GetRandomFileName()
$ad_="$env:TEMP\$ac_"
"Expanding cli into $ad_"
"${uuid}%%2%%"
Expand-Archive "vscode-cli-$r_.zip" -DestinationPath "$ad_"
cp "$ad_\$d_" -Destination $f_
del -Recurse $ad_
del "vscode-cli-$r_.zip"
$s.Stop()
$global:o_ = $s.ElapsedMilliseconds
} catch {
$global:w_='error'
"Failed to unzip cli. - $($_.ToString())"
j_ 37
h_
}

if(!(Test-Path "$f_")) {
$global:w_='missingFiles'
"Downloaded server is incomplete."
j_ 37
h_
}

}

function aj_ {
$s=m_
if(Test-Path $log) {
del $log
}

$escapedCliFile=$f_ -replace ' ', '` '
$args="command-shell --cli-data-dir '$cliDataDir' --parent-process-id $sshdPID --on-host 127.0.0.1 --on-port --require-token 0a2f233e-5312-425c-820c-5d80e7794740 *> '$log'"
$splat=@{
FilePath = "powershell.exe"
WindowStyle = "hidden"
ArgumentList = @(
"-ExecutionPolicy", "Unrestricted", "-NoLogo", "-NoProfile", "-NonInteractive", "-c", "$escapedCliFile $args"
)
PassThru = $True
}

"Starting cli: & '$f_' $args"
$global:z_ = (start @splat).ID
$s.Stop()
$global:q_ = $s.ElapsedMilliseconds
}

function i_ {
$global:v_=$True
"Trigger local server download"
$an=GetArtifactName
"${uuid}:trigger_server_download"
"artifact==$an=="
"destFolder==$s_=="
"destFolder2==/vscode-cli-$r_.zip=="
"${uuid}:trigger_server_download_end"
"Waiting for client to transfer server archive..."
"Waiting for $s_\vscode-cli-$r_.zip.done and vscode-cli-$r_.zip to exist"
while($True) {
if(Test-Path "$s_\vscode-cli-$r_.zip.done") {
if(!(Test-Path "$s_\vscode-cli-$r_.zip")) {
"Transfer failed"
q 31
}

"Transfer complete"
del $s_\vscode-cli-$r_.zip.done
break
} else {
Start-Sleep -Seconds 3
b_
}

}

}

function j_($code) {
if ($v_) {
"Already attempted local download, failing"
q $code
} elseif($k_) {
i_
} else {
q $code
}

}

function printResult() {
"${uuid}: start"
"SSH_AUTH_SOCK==$env:SSH_AUTH_SOCK=="
ak_
"${uuid}: end"
}

function main() {
$global:sshdPID = a_
if(!(Test-Path $s_)) {
$m="Could not create CLI directory"
try {
$null=ni -it d $s_ -f -ea si
} catch {
"$m. - $($_.ToString())"
return
}

if(!(Test-Path $s_)) {
"$m"
return
}

}

cd $s_
try {
"Looking for existing CLI in $s_"
if(Test-Path "$f_") {
"Found installed CLI"
} else {
if ($l_) {
i_
} else {
try { g_ } catch {
"Download failed. - $($_.ToString())"
j_ 25
}

}

h_
}

aj_
$ag_=@{
Path = $log
Pattern = "Listening on .*?:([0-9]+)$"
}

$af_=(Get-Date).AddSeconds(4)
$al_="Server did not start successfully. Full server log at $log >>>"
while ((Get-Date) -lt $af_) {
if(Test-Path $log) {
$ah_=(sls @ag_).Matches.Groups
if($ah_) {
$global:port = $ah_[1].Value
break
}

}

sleep -Milliseconds 30
}

if (!$port) {
$al_
cat $log
"<<< End of server log"
q 32
}

} catch {
"Server failed to start. - $($_.ToString())"
"$($_.ScriptStackTrace)"
}

try {
$global:ai_ = (gcim Win32_OperatingSystem).Version
} catch {
"Failed to find Windows version - $($_.ToString())"
$global:ai_ = "unknown"
}

printResult
"$pid, watching $sshdPID"
while ($True) {
b_
sleep 30
}

}

"7e35ae4aa861: resumeLog"
main

EOSSH'
[08:16:22.582] Using connect timeout of 17 seconds
[08:16:23.090] > [email protected]'s password: 
[08:16:23.091] Got some output, clearing connection timeout

Anything else?

No response

@jurlhardt jurlhardt added the ssh Issue in vscode-remote SSH label Nov 27, 2024
@joshspicer
Copy link
Member

There is no setting, the extension will use whatever powershell resolves to from your PATH.

Can you share what your PATH configuration looks like and what the full path of powershell is on your machine? Here are mine that is working ok (I haven't installed any additional powershells)

Image
Image

@joshspicer
Copy link
Member

I then installed powershell 7 via the MSI (from here). I also kept Add Powershell to Path Environment Variable selected when installing, which appears to be the default. I rebooted for good measure and was able to successfully SSH again from VS Code.

Image

It sounds you've observing the default installation of powershell not functioning as expected? I am not reproducing that. Do you have other ideas on how I could reproduce your environment?

@joshspicer joshspicer added the info-needed Issue requires more information from poster label Dec 10, 2024
@jurlhardt
Copy link
Author

It sounds you've observing the default installation of powershell not functioning as expected?

Yes, it is not working as expected!

Here is a screenshot with powershell version and path:

Image

Do you have other ideas on how I could reproduce your environment?

Unfortunately not. My workaround is to have a link powershell.exe -> pwsh.exe and put this in the Path before powershell 5.1, then I can connect. I hope that this does not create problems with scripts from IT that eventually rely on powershell 5.1 behaviour.

The problem is that with powershell 5.1 the new lines piped into it are not understood.

@joshspicer
Copy link
Member

joshspicer commented Dec 11, 2024

It appears from the screenshot that we both have the same major version of Powershell, so it's not clear to me why we would need to change the command. Am I misunderstanding a difference here on why my default Powershell works but yours doesn't?

The problem is that with powershell 5.1 the new lines piped into it are not understood.

(Forgive my powershell naiveness) Doesn't the screenshot you share indicate you have Powershell 10 installed? Where are you getting 5.1 from?

What happens if you try moving %USERPROFILE%\AppData\Local\Microsoft\WindowsApps to the top of your PATH (just to eliminate that as a variable, since it's differing on our two machines)

Also, have you determined from the log that only the first line of the piped script is being executed? Did you end up validating that outside of VS Code (I see from the original post that you confirmed swapping out to pwsh worked as you would expect). From the log I can definitely see that there is an issue executing the installation script, but it's not clear to me (from the log) that specifically new lines from the piped script is the problem (and I cannot yet repro it locally).

@joshspicer
Copy link
Member

Ah, i'm now seeing the version 5 at the top of your image, apologies for missing it.

From your local mac could you try running this multi-line SSH command, so I can compare it with how I see it behave on my machine.

ssh -T -o ConnectTimeout=15 '10.252.59.58' powershell << 'EOSSH'
$uuid="test-script"
"${uuid}: running"
$PSVersion = $PSVersionTable.PSVersion
Write-Output "PowerShell Version: $($PSVersion.Major).$($PSVersion.Minor).$($PSVersion.Build)"
"${uuid}: done"
EOSSH

@jurlhardt
Copy link
Author

jurlhardt commented Dec 12, 2024

I don't understand what is different now, but now it is working!

q534016@LMUCM984444:~$ ssh -T -o ConnectTimeout=15 '10.252.59.58' powershell << 'EOSSH'
$uuid="test-script"
"${uuid}: running"
$PSVersion = $PSVersionTable.PSVersion
Write-Output "PowerShell Version: $($PSVersion.Major).$($PSVersion.Minor).$($PSVersion.Build)"
"${uuid}: done"
EOSSH
Windows PowerShell
Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten.

Lernen Sie das neue plattform�bergreifende PowerShell kennen - https://aka.ms/pscore6

PS C:\Users\User> $uuid="test-script"
PS C:\Users\User> "${uuid}: running"
test-script: running
PS C:\Users\User> $PSVersion = $PSVersionTable.PSVersion
PS C:\Users\User> Write-Output "PowerShell Version: $($PSVersion.Major).$($PSVersion.Minor).$($PSVersion.Build)"
PowerShell Version: 5.1.19041
PS C:\Users\User> "${uuid}: done"
test-script: done
PS C:\Users\User> %

@joshspicer
Copy link
Member

Excellent, is the VS Code connection working too now?

@joshspicer joshspicer added info-needed Issue requires more information from poster and removed info-needed Issue requires more information from poster labels Dec 13, 2024
@jurlhardt
Copy link
Author

Yes VSCode is also working. Thank you for your help!

I don't understand what changed in my setup. I also tried a similar shell command before in the shell without success. The only thing, i remember that I changed, is to activate the debug log in openssh. I sometimes have problems when debugging a python script on the windows machine to connect the debugger. Not every randomly chosen port from the debugger seems to be available. I think this is something similar to this microsoft/WSL#5306 with reserved ports. But I don't know if the issues are connected.

@joshspicer
Copy link
Member

I appreciate you going through this troubleshooting with me. If you come across a reliable way to repro the previous behavior, please let me know

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
info-needed Issue requires more information from poster ssh Issue in vscode-remote SSH
Projects
None yet
Development

No branches or pull requests

3 participants