My remote machine is a windows and I am doing ssh from ubuntu to windows.

I want to use git bash instead of command prompt, but running the ssh will bring me to the default command prompt, is there any way that I could invoke git bash through ssh?

I try the following command not working:

ssh Administrator@54.xxx.xxx.207 < "C:\Program Files\Git\bin\sh.exe"

I can run the following command to after ssh to start the git bash, but I am seeking a way to automate this process?

"C:\Program Files\Git\bin\sh.exe" --login

I am using Windows 2012 R2

  • 1
    You should specify the version of Windows you're using on your server. Since Windows 10, you can easily install bash and most certainly openssl along a Linux SSH server. On older systems, you may have to install Cygwin to make it possible to run SSH in a bash shell. – Alexis Wilke Dec 17 '19 at 22:30
  • I am using Windows 2012 R2 – Tiger Dec 18 '19 at 14:49

Yes, you can if you have OpenSSH For Windows Server 2019 and Windows 10 installed.

From OpenSSH Server Configuration for Windows 10 1809 and Server 2019:

Configuring the default ssh shell is done in the Windows registry by adding the full path to the shell executable to Computer\HKEY_LOCAL_MACHINE\SOFTWARE\OpenSSH in the string value DefaultShell.

As an example, the following Powershell command sets the default shell to be PowerShell.exe:

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

To set Git Bash as default shell, run this snippet as administrator in the PowerShell:

New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Program Files\Git\bin\sh.exe" -PropertyType String -Force

To get a login shell, you could create a batch file sh.bat in C:\Program Files\Git\bin with this content:

@echo off
"C:\Program Files\Git\bin\sh.exe" --login

and replace the DefaultShell value with C:\Program Files\Git\bin\sh.bat.

The DefaultShell registry key is a new key, you can delete it to restore the default command prompt.

| improve this answer | |
  • thank you, this works for me – Tiger Dec 18 '19 at 19:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.