方式一:将 SSH 登录默认改为 PowerShell(推荐)
PowerShell(管理员)执行
New-ItemProperty `
-Path "HKLM:\SOFTWARE\OpenSSH" `
-Name "DefaultShell" `
-Value "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" `
-PropertyType String -Force
完成后重启 sshd 服务:
Restart-Service sshd
再次SSH登录
方式二:使用 PowerShell 7(推荐新环境)
如果你安装了 PowerShell 7(pwsh),路径一般为:
C:\Program Files\PowerShell\7\pwsh.exe
设置默认 shell:
New-ItemProperty `
-Path "HKLM:\SOFTWARE\OpenSSH" `
-Name "DefaultShell" `
-Value "C:\Program Files\PowerShell\7\pwsh.exe" `
-PropertyType String -Force
完成后重启 sshd 服务:
Restart-Service sshd
再次SSH登录
方式三:临时进入 PowerShell(不修改默认 shell)
即使默认是 CMD,你也可以在 SSH 后手动执行:
powershell
或使用 pwsh:
pwsh
但这只是临时进入,退出后回到 CMD,不适合作为日常运维。