Vagrant ssh -c against Windows box runs bash instead of powershell.exe or cmd.exe

It’s been almost five years and the Vagrant bug seems still there, apparently, as the semantic of vagrant ssh -c <cmd> gets broken for every Windows box with installed OpenSSH due to the bash -l being hard-wired.

Having no config.ssh.shell in Vagrantfile, I’ve tried vagrant --debug ssh -c dir, here are the logs showing bash -l

  1. vagrant-ssh-bug-with-defaultshell-powershell.txt with New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -PropertyType String -Force

    INFO ssh: Executing SSH in subprocess: C:\WINDOWS\System32\OpenSSH\/ssh.EXE
    ["vagrant@127.0.0.1", "-p", "2222", "-o", "LogLevel=FATAL", "-o", "Compression=yes", "-o", "DSAAuthentication=yes", "-o", "IdentitiesOnly=yes", "-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile=/dev/null", "-i", "C:/Users/MateuszL/.vagrant.d/insecure_private_key",
    "-t", "bash -l -c 'dir'"]
    
  2. vagrant-ssh-bug-without-defaultshell.txt without DefaultShell property

     INFO ssh: Executing SSH in subprocess: C:\WINDOWS\System32\OpenSSH\/ssh.EXE
    ["vagrant@127.0.0.1", "-p", "2222", "-o", "LogLevel=FATAL", "-o", "Compression=yes", "-o", "DSAAuthentication=yes", "-o", "IdentitiesOnly=yes", "-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile=/dev/null", "-i", "C:/Users/MateuszL/.vagrant.d/insecure_private_key",
    "-t", "bash -l -c 'dir'"]
    

The only way to get the vagrant ssh execute a (simple!) command is vagrant ssh -- dir as per fix defaults for vagrant ssh -c on windows guests by mcandre · Pull Request #9483 · hashicorp/vagrant · GitHub which is not a solution!

Another workaround is vagrant winrm -c 'dir', still, not a solution, is it?

Hi,

Apologies for the delayed response on this. I left a response about this on the issue you linked to.

Cheers!