logo

How to Change the Default Shell to PowerShell When Connecting to a Windows Server via SSH 📂Programing

How to Change the Default Shell to PowerShell When Connecting to a Windows Server via SSH

Guide

When you set up an SSH server on Windows and connect to it, the default shell program is cmd.exe. Not only do commands like ls and pwd not work, but you also cannot move between drives with the cd command, which is very inconvenient, and you have the further hassle of having to type the powershell command to enter PowerShell.

This can be solved on the server side by running a terminal with administrator privileges and editing the registry with the following command.

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

If the following output is printed, the registry has been edited successfully.

PS C:\Users\admin> New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -PropertyType String -Force


DefaultShell : C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
PSPath       : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\OpenSSH
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE
PSChildName  : OpenSSH
PSDrive      : HKLM
PSProvider   : Microsoft.PowerShell.Core\Registry

For reference, this output is based on PowerShell 11.