Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git with SSH on Windows

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 
like image 439
pankar Avatar asked Mar 23 '10 11:03

pankar


People also ask

Does Git for Windows install SSH?

Yes, Git for Windows installs its own SSH client. It ships a version of OpenSSH with the package. If you're seeing /usr/bin/ssh when you run command -v ssh , then you're using the version from Git for Windows.

How do I use SSH with Git?

Verify which remotes are using SSH by running git remote -v in your Git client. Visit your repository on the web and select the Clone button in the upper right. Select SSH and copy the new SSH URL. In your Git client, run: git remote set-url <remote name, e.g. origin> <new SSH URL> .

Where does Git for Windows Store SSH keys?

The default location is: %HOMEDRIVE%%HOMEPATH%\. ssh\id_rsa. pub . That would expand to something like C:\Users\dennis\.


2 Answers

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.

Hope this helps.

like image 68
Todd Avatar answered Sep 21 '22 22:09

Todd


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

like image 21
jaygeek Avatar answered Sep 19 '22 22:09

jaygeek