如何将Windows 10 Pro的OpenSSH默认Shell从cmd.exe改为PowerShell
如何将Windows 10 Pro的OpenSSH默认Shell从cmd.exe改为PowerShell
我来帮你搞定这个问题!你之前修改Subsystem配置的操作,其实是用来定义PowerShell子系统的(也就是当你从客户端执行ssh user@host powershell这类命令时才会触发),并不是设置默认登录后的shell。要让SSH登录后直接进入PowerShell,得从默认shell的配置入手,下面是两种靠谱的方法:
方法一:通过PowerShell命令快速设置(推荐)
- 打开管理员权限的PowerShell(右键开始菜单选择“Windows PowerShell (管理员)”)
- 执行以下命令来设置默认Shell:
New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -PropertyType String -Force - 重启OpenSSH服务使配置生效:
Restart-Service sshd
方法二:手动修改sshd_config配置文件
- 找到OpenSSH的配置文件:
C:\ProgramData\ssh\sshd_config(注意你之前可能写错了文件名,应该是sshd_config而非sshd) - 用文本编辑器(比如Notepad++)打开该文件,找到
DefaultShell配置项(如果没有就手动添加一行):DefaultShell C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe - 保存文件后,重启OpenSSH服务:
Restart-Service sshd
完成以上操作后,重新通过SSH登录你的Windows主机,应该就能直接进入PowerShell环境了!
备注:内容来源于stack exchange,提问作者Intrastellar Explorer




