如何为 OpenSSH 配置 powershell 而不是 cmd

Int*_*rer 2 windows ssh powershell openssh sshd

我有一台 Windows 10 Pro 计算机,我可以ssh将其作为cmd. 我希望将 shell 设置为powershell.exe(不是默认的cmd.exe)。

C:\ProgramData\ssh\sshd我尝试在本文设置以下内容,然后设置Restart-Service sshd,但这不起作用:

Subsystem   powershell  c:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -sshs -NoLogo -NoProfile
Run Code Online (Sandbox Code Playgroud)

这也不起作用:

Subsystem   powershell  C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -sshs -NoLogo -NoProfile
Run Code Online (Sandbox Code Playgroud)

我已经确认C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exePowerShell的位置正确。

如何使 shell 成为 PowerShell 以ssh访问 Windows 主机?

use*_*686 5

Subsystem并不意味着更改您的默认 shell,恰恰相反 \xe2\x80\x93 它定义了客户端必须显式请求的命令。(它实际上是服务器端别名。)

\n

因此,您找到的配置片段并不意味着改变您从常规中获得的内容ssh;它的目的是允许本地 PowerShell 实例调用 SSH 客户端并在服务器上启动远程 PowerShell,而无需知道其路径(它需要指定的只是子系统名称)。

\n

具体来说,该-sshs选项表明它适用于使用或cmdlet通过 SSH 进行PSRemoting,该 cmdlet 可以通过 SSH 在 PowerShell\xc2\xa07 中运行。Enter-PSSessionInvoke-Command

\n
PS> Enter-PSSession -HostName otherpc\n[otherpc] PS>\n
Run Code Online (Sandbox Code Playgroud)\n

-HostName选项使其使用 SSH,而-ComputerName使其使用 WinRM。)

\n

(这在 PowerShell 5 \xe2\x80\x93 中不起作用,其 PSRemoting 支持只能通过 WinRM运行,但如果您需要 PowerShell,那么 WinRM 实际上是 SSH 的不错替代品。)

\n
\n

实际上,更改 Windows OpenSSH(Microsoft 官方版本)中的默认 shell 是完全不同的 \xe2\x80\x93 它在此页面上记录

\n
PS> Enter-PSSession -HostName otherpc\n[otherpc] PS>\n
Run Code Online (Sandbox Code Playgroud)\n