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]>