views:

805

answers:

2

I'm setting up git on my new Windows 7 machine and I'm hitting a roadblock when it comes to getting github to acknowledge my ssh key. I am doing things a little different from the standard script in that I would rather not use cygwin and prefer to use my powershell prompt. The following is what I did:

  1. I installed msysgit (portable).
  2. I went to C:\program files\git\bin and used ssh-keygen to generate a public/private ssh keypair which I put in c:\Temp
  3. I then created a directory named .ssh\ in c:\Users\myusername\ (on windows 7)
  4. I moved both the files generated by the ssh-keygen (id_rsa and id_rsa.pub) into the .ssh directory
  5. I went to my account on github, created a new public key, copy-pasted the contents of id_rsa.pub into it and saved
  6. I now go to my powershell prompt, set-alias git 'C:\program files\git\bin\git.exe'
  7. I try to now do a clone [email protected]:togakangaroo/ps-profile.git which rejects my authentication:

    Permission denied (publickey). fatal: The remote end hung up unexpectedly

Past experience says that this means git is not recognizing my key. What steps am I missing?

I have a feeling that I need to somehow configure git so that it knows where my ssh keys are (though it would seem it should look there automatically) but I don't know how to do that.

Another possible clue is that when I try to run git config --global user.name "George Mauer" I get an error

fatal: $HOME not set

I did however set up a HOME environment user variable with the value %HOMEDRIVE%%HOMEPATH%

+2  A: 

The command you're looking for is: ssh-add C:\path\to\key

First, you may want to find out where ssh is currently looking for your keys, by running ssh -v [email protected]

Nick Novitski
are ssh and ssh-add utilities that are in the git\bin directory? I'm not using bash here
George Mauer
Sorry, spoke too soon, I see that they are there. I get this when I run ssh: http://pastebin.com/G6FPN9As What in the world does it all mean?
George Mauer
It looks like ssh is looking for the keys in C:\program files\git\bin\.ssh. The simplest solution would be to copy the keys to that directory. But if you like where they are, then run ssh-add c:\Users\myusername\.ssh .
Nick Novitski
I think I'd prefer to keep it well organized - but running ssh-add gives me "Could not open a connection to your authentication agent."
George Mauer
Try setting the path to include the portable installation's cmd directory: `set path=c:\yourpath\portablegit\cmd;%path%`. See if that temporarily helps ssh-add or git-config work.
Nick Novitski
+5  A: 

I had the same problem. I accidently added the wrong directory to the path.

After I changed that from *\Git\bin\ to *\Git\cmd\ everything worked.

git.cmd sets up the environment variables.

Christian Deger