11

I have a Windows 10 Pro machine that I can ssh into (OpenSSH Server is installed/running) as cmd. I want to have the shell as powershell.exe (not the default of cmd.exe).

I tried setting the following in C:\ProgramData\ssh\sshd per this article, followed by Restart-Service sshd, but this doesn't work:

Subsystem   powershell  c:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -sshs -NoLogo -NoProfile

Nor does this work:

Subsystem   powershell  C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -sshs -NoLogo -NoProfile

I have confirmed C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe to be the correct location of PowerShell.

How can I get the shell to be PowerShell for sshing into a Windows host?

1 Answers1

18

Subsystem is not meant to change your default shell, quite the opposite – it defines a command that clients have to explicitly request. (It's literally a server-side alias.)

So the configuration snippet you found wasn't meant to change what you get from regular ssh; it's meant to allow a local PowerShell instance to invoke the SSH client and start a remote PowerShell on the server, without having to know its path (all it needs to specify is the subsystem name).

Specifically, the -sshs option indicates that it's meant for PSRemoting over SSH using the Enter-PSSession or Invoke-Command cmdlets, which can run via SSH in PowerShell 7.

PS> Enter-PSSession -HostName otherpc
[otherpc] PS>

(-HostName option makes it use SSH, whereas -ComputerName makes it use WinRM.)

(This won't work in PowerShell 5 – its PSRemoting support can only run via WinRM, though if you want PowerShell then WinRM is actually not a bad alternative to SSH.)


Actually changing the default shell in Windows OpenSSH (the official Microsoft builds) is done completely differently – it's documented on this page:

New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" `
                 -Name DefaultShell `
                 -Value "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" `
                 -PropertyType String `
                 -Force
grawity
  • 501,077