My warm recommendation is to use Cygwin to accept ssh connections on your Windows machine. This would allow you to scp to and from it, as well as login from a remote system via ssh to a Bash shell and command-line git.
user@linuxhost$ ssh 192.168.x.x
Last login: Sun Feb 12 08:20:07 2017 from 10.x.x.x
user@windowshost$ echo $0 && git --version
-bash
git version 2.8.3
The shell can of course be customized: ash, bash, dash and sh are included by default, but just run the Cygwin installer and you can add your choice of zsh, mksh, tcsh or posh. Then add the following line to /etc/nsswitch.conf
:
db_shell: /bin/sh
possibly substituting /usr/bin/sh
with the path to your preferred shell. All Cygwin processes (terminal windows and sshd service) must be restarted for the setting to take effect.
There is even a way to get a cmd or powershell prompt upon login, which I recently found out about on Stackoverflow.
- Download winpty for Cygwin and extract
winpty.exe
, winpty.dll
and winpty-agent.exe
to /bin
. If you do this from outside of a Cygwin terminal, look for a bin
subdirectory of the Cygwin installation folder.
Create two batch files in /bin
and make sure they have execute permissions. Let's name them winpty-cmd.bat and winpty-powershell.bat and fill them with the following contents, where of course <cygwin path>
is a placeholder for the path you installed Cygwin to (by default it's C:\cygwin
):
@ECHO OFF
<cygwin path>\bin\winpty.exe cmd
and
@ECHO OFF
<cygwin path>\bin\winpty.exe powershell
Put one of these lines into /etc/nsswitch.conf
:
db_shell: /bin/winpty-cmd.bat
or
db_shell: /bin/winpty-powershell.bat
- Restart the sshd service.
Since the title has been "reworded" and my post might now seem sligthly out of place, allow me to directly answer the original question:
"Use git bash instead of cmd when sshing from Linux"
In addition to using Cygwin to accept ssh connections on the Windows machine:
- Follow step
1.
above.
Create a file called <cygwin path>\bin\winpty-gitbash.bat
with these contents, where <cygwin path>
is a placeholder for the path you installed git-for-windows to (by default it's C:\Program Files\Git
):
@ECHO OFF
SET PATH="/bin"
<cygwin path>\bin\winpty.exe "<git path>\bin\bash.exe"
Put this line into /etc/nsswitch.conf
:
db_shell: /bin/winpty-gitbash.bat
- Restart the sshd service.
Update - September 2018:
Things change, and Win32-OpenSSH now allows choosing the default shell (any shell actually) by setting its path in a registry key. See Brethlosze's recent answer.
You can do this easier with a dedicated tool. See for example if you like Gitblit.
– harrymc – 2017-02-27T20:26:18.963