添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

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

Please answer the following

"OpenSSH for Windows" version
((Get-Item (Get-Command sshd).Source).VersionInfo.FileVersion)
7.7.2.2

Server OperatingSystem
((Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows nt\CurrentVersion\" -Name ProductName).ProductName)
Windows Server 2019 Datacenter Evaluation

Client OperatingSystem
macOS 10.14.4

What is failing
Running the following command cmd /c ver through SSH does not work.

Expected output

Microsoft Windows [Version 10.0.17763.437]                                      

Actual output

'ver"' is not recognized as an internal or external command,
operable program or batch file.

When I looked closer I saw a double quote ver".

So I tried a little more:

$ ssh -p 2222 User03@localhost cmd /c ver
User03@localhost's password:
'ver"' is not recognized as an internal or external command,
operable program or batch file.
$ ssh -p 2222 User03@localhost "cmd /c ver"
User03@localhost's password:
'ver"' is not recognized as an internal or external command,
operable program or batch file.
$ ssh -p 2222 User03@localhost "cmd /c ver "
User03@localhost's password:
Microsoft Windows [Version 10.0.17763.437]

When I append a blank to my command then it works.

This command cmd /c ver is used by InSpec to recognize a Windows backend. I want to add SSH support for Windows in InSpec with inspec/train#416 but struggle with that tiny difference. The original OpenSSH Windows port does not have this problem, only this native port seems to add quotes. I added a workaround to call ver in my PR if cmd /c ver fails, but then we need two commands to detect Windows.
The detection is also used for WinRM connects, that's why cmd /c ver is used to start a cmd.exe from within the PowerShell session.

I have also prepared a Windows Container image with a test user User03 and Passw0rd to have a portable test environment to reproduce the problem.

$ docker run -d -p 2222:22 stefanscherer/openssh-windows
$ ssh -p 2222 User03@localhost cmd /c ver
User03@localhost's password:
'ver"' is not recognized as an internal or external command,
operable program or batch file.
          

If you do cmd.exe /c var it should work as it starts the new executable cmd.exe. When debugging the command the process that is actually run is C:\Windows\System32\cmd.exe /c "cmd /c ver". Command prompt has some weird rules around quoting and making sure you specify the extension seems to be enough to get around that.

You could also just do ssh user@host ver as the default shell is already cmd but that might be a bit inflexible as users can change their shell.

Thanks @jborean93 I'll try that.

The cmd /c ver is needed as the InSpec/train module also supports WinRM and then lands in a PowerShell session. Therefore it has to start a cmd shell to finally run the ver command.

But cmd.exe /c ver should work for all scenarios there.

Mutagen was previously unable to probe Windows systems using the
official Windows OpenSSH server due to PowerShell/Win32-OpenSSH#1373.
This should fix the issue.
Updates #252.
Signed-off-by: Jacob Howard <[email protected]>