64

I've went through the excellent guide provided by Tim Davis which is about configuring Git to work with SSH under Windows in order to produce a Git Server in order to have a main place for my DVCS.

I am in the process of creating a clone for my project. I’ve went through all the steps till this point, but I keep getting this from TortoiseGit:

git.exe clone -v “ssh://[email protected]:22/SSH/Home/administrator/myapp.git” “E:\GitTest\myapp”

bash: [email protected]: command not found
Initialized empty Git repository in E:/GitTest/myapp/.git/
fatal: The remote end hung up unexpectedly
Success

and nothing gets cloned.

BTW: The TortoisePLink comes up just before this message appears and asks me: “login as:” ( I thought that this info is given in the command, i.e: Administrator@blahblah.

My home variable is set to the correct place: From a Git Bash shell:

echo $HOME
/c/SSH/home/Administrator

I’ve also tried using Putty’s plink instead of TortoisePLink (in both Git’s and TortoiseGit’s installation). This time the error was narrowed down to:

git.exe clone -v “ssh://[email protected]:22/c:/SSH/Home/administrator/myapp.git” “E:\GitTest\myapp”

Initialized empty Git repository in E:/GitTest/myapp/.git/
fatal: The remote end hung up unexpectedly
4
  • 1
    The link in your question is broken... Commented Nov 22, 2017 at 20:42
  • 1
    Wayback Machine to the rescue! web.archive.org/web/20170507103323/http://www.timdavis.com.au/… Commented Dec 6, 2017 at 11:24
  • Link fixed to point to the article's new page. However, Git for Windows bundles OpenSSH now so that might be a better alternative than Cygwin's OpenSSH. Commented Apr 6, 2021 at 22:02
  • Since Putty 0.77 it get's much easier without PLINK and other extra tools. See also stackoverflow.com/a/74394215/9258377 Commented Nov 11, 2022 at 9:38

10 Answers 10

135

I fought with this problem for a few hours before stumbling on the obvious answer. The problem I had was I was using different ssh implementations between when I generated my keys and when I used git.

I used ssh-keygen from the command prompt to generate my keys and but when I tried "git clone ssh://..." I got the same results as you, a prompt for the password and the message "fatal: The remote end hung up unexpectedly".

Determine which ssh windows is using by executing the Windows "where" command.

C:\where ssh
C:\Program Files (x86)\Git\bin\ssh.exe

The second line tells you which exact program will be executed.

Next you need to determine which ssh that git is using. Find this by:

C:\set GIT_SSH
GIT_SSH=C:\Program Files\TortoiseSVN\bin\TortoisePlink.exe

And now you see the problem.

To correct this simply execute:

C:\set GIT_SSH=C:\Program Files (x86)\Git\bin\ssh.exe

To check if changes are applied:

C:\set GIT_SSH
GIT_SSH=C:\Program Files (x86)\Git\bin\ssh.exe

Now git will be able to use the keys that you generated earlier.

This fix is so far only for the current window. To fix it completely you need to change your environment variable.

  1. Open Windows explorer
  2. Right-click Computer and select Properties
  3. Click Advanced System Settings link on the left
  4. Click the Environment Variables... button
  5. In the system variables section select the GIT_SSH variable and press the Edit... button
  6. Update the variable value.
  7. Press OK to close all windows

Now any future command windows you open will have the correct settings.

Sign up to request clarification or add additional context in comments.

3 Comments

I've had git-bash working on Windows10 with git remote push/pull all the time, until moments ago, getting error "error: cannot spawn ssh: No such file or directory". This answer above inspired my fix, on git-bash: export GIT_SSH=/c/Program\ Files/Git/usr/bin/ssh.exe, then git push origin started working magically. Thanks!
Now that OpenSSH is included in Windows 10, the answer to solving this is to tell git to use OpenSSH. Git, by default, uses its own bundled ssh.exe on Windows. To fix for yourself, use: setx GIT_SSH C:\Windows\System32\OpenSSH\ssh.exe. To fix for everyone on the computer, pass the /M flag to setx.
The procedure described above works in 2022 on Windows 10. Please check this thread as well to get an idea how to enable OpenSSH Authentication Agent (see the most rated answer).
24

Since this keeps coming up in search results for making git and github work with SSH on Windows (and because I didn't need anything from the guides above), I'm adding the following, simple solution.

(Microsoft says they are working on adding SSH to Visual Studio, and GitHub for Windows still doesn't support SSH...)

1. I installed "git for Windows" (which includes ssh and a bash shell)

https://git-scm.com/download/win

2. From the included bash shell (which, for me, was installed at: C:\Program Files\Git\git-bash.exe)

cd to the root level of where you want your repo saved (something like: C:\code\github\), and

Type:

eval $(ssh-agent -s) && ssh-add "C:\Users\YOURNAMEHERE\.ssh\github_rsa"

3. Type: (the SSH link from the repo)

git clone [email protected]:RepoName/Project.git

5 Comments

Any idea why you have to wrap the ssh-agent in eval to make it work?
@Fractalf that's how it's designed. ssh-agent -s generates shell code, and eval "$(ssh-agent -s)" runs the generated code.
this is the ONLY solution that's worked for me, everything else on windows for cloning says to use https:// formats which never use key authentication. thanks!
What does 'eval $(ssh-agent -s) && ssh-add "C:\Users\YOURNAMEHERE\.ssh\github_rsa"' do? Why do you need it? I want to use the OpenSSH which is included in Windows but after successful login clone is canceled with "fatal: ''C:/path to bare git repository'' does not appear to be a git repository"...
This still is the only solution that works for me in 2024. Thanks so much
9

you are using a smart quote instead of " here:

git.exe clone -v “ssh://
                ^^^ 

Make sure you use the plain-old-double-quote.

Comments

6

I've found my ssh.exe in C:/Program Files/Git/usr/bin directory.

Comments

4

If Git for windows is installed, run Git Bash shell:

  bash

You can run ssh from within Bash shell (Bash is aware of the path of ssh)

To know the exact path of ssh, run "where" command in Bash shell:

  $ where ssh

you get:

  c:\Program Files\Git\usr\bin\ssh.exe

1 Comment

great!! very useful
4

When I typed where ssh it showed me multipe ssh.exe

user@pc MINGW64 /c/dev/
$ where ssh
C:\Users\user\AppData\Local\Programs\Git\usr\bin\ssh.exe
C:\Windows\System32\OpenSSH\ssh.exe

Deleting / moving these exe helped:

# copy from
# C:\Users\user\AppData\Local\Programs\Git\usr\bin
# to something like
# C:\Users\user\AppData\Local\Programs\Git\usr\bin\backup-ssh
ssh-agent.exe
ssh.exe
ssh-add.exe

This solved the issue for me.

1 Comment

I used mv command to rename each file. Example: "mv ssh.exe backup_ssh.exe" make sure to run bash in administrator mode.
3

I was trying to solve my issue with some of the answers above and for some reason it didn't work. I did switch to use the git extensions and this are the steps I did follow.

  1. I went to Tools -> Settings -> SSH -> Other ssh client
  2. Set this value to C:\Program Files\Git\usr\bin\ssh.exe
  3. Apply

I guess that this steps are just the same explained above. The only difference is that I used the Git Extensions User Interface instead of the terminal. Hope this help.

Comments

1

In case it helps anyone, I needed Git to use the Windows's included OpenSSH, because of using a Nitrokey smartcard with GnuPG keys and gpg-agent (not relevant to this question).

After cheking it worked with:

set GIT_SSH=C:\Windows\System32\OpenSSH\ssh.exe

I only had to add it to the environment variables in My Computer => Properties => Advanced Properties => Environment

Comments

0

not sure if my answer makes sense here.. but I got the same issue with GIT_SSH pointing to TortoisePlink.exe. I got it solved by going to options of SourceTree tool where I accidently somehow configured SSH Client Configuration for SSH Client to Putty/Plink. I guess it was the default. When I changed it to OpenSSH I was able to clone my repo from Bitbucket.

Comments

0

You can also configure the SSH client to use in git itself with the core.sshCommand option:

git config set --global core.sshCommand "C:\\Windows\\System32\\OpenSSH\\ssh.exe"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.