logo

WindowsサーバーにSSHで接続する際のデフォルトシェルをPowerShellに変更する方法 📂プログラミング

WindowsサーバーにSSHで接続する際のデフォルトシェルをPowerShellに変更する方法

ガイド

WindowsでSSHサーバーを構築して接続する場合、デフォルトのシェルプログラムがcmd.exeであるため、lsやpwdのようなコマンドが使えないのはもちろん、cdコマンドでドライブ間を移動することもできず非常に不便であり、powershellコマンドを入力してPowerShellに入らなければならない手間がある。

これは、サーバー側でターミナルを管理者権限で実行した後、次のコマンドでレジストリを編集することで解決できる。

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

次のような実行結果が出力されれば、レジストリは正常に編集されている。

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

なお、この結果はPowerShell 11を基準としている。