8

There are many fine instructions about how to work with git under windows using GitBash.

I note that when git is installed, it offers the option of "set up for using git from the windows prompt", which puts git on the windows path.

Is there some way to set this up so that ssh authentication works?

At the moment I get "permission denied (publickey)" when I try to do git commands that access the remote.

(edit) I have set %HOME% to point to my Windows home directory, and there is a .ssh folder in there with id files that work under a gitbash shell.

I appreciate that the answer is likely "no, this is why GitBash exists". But - it would be good to know for sure.

If the answer is "no" it kinda makes you wonder why you would bother putting git on your windows path?

GreenAsJade
  • 14,459
  • 11
  • 63
  • 98
  • I don't understand your question? Why would it not be a good idea to have `git` in the windows path?? You like typing the entire path to git everytime you commit changes? – PeeHaa Sep 07 '13 at 00:54
  • 1
    I guess this point is an aside to the main question. I was thinking that if you have to use gitbash to run commands that access the repository using ssh (which is my current problem), then that kinda means you are going to be using gitbash all the time, rather than a windows console. Otherwise it seems that you will be doing some git work in the windows command line and other in gitbash (which is what I am trying to avoid). – GreenAsJade Sep 07 '13 at 04:44

2 Answers2

4

ssh access works fine from a regular DOS session.
You only need to define C:\Users\YourAccount\.ssh and add your id_rsa and id_rsa.pub there.

Launch your git session through git-cmd.bat, which will define %HOME% to your C:\Users\YourAccount: that is what will make ssh work.

This should put your msysgit/bin installation in your PATH.

I really recommend not installing through a msi (Microsoft Installer), but through a simple unzip of an archive (portable version "PortableGit-x.y.z-preview201ymmdd.7z")

And the OP GreenAsJade's comment points out the fact that GIT_SSH must point to plink.exe.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks for your answer! It's great to know that this should work. I have a .ssh folder in my home directory, and it has id_rsa and id_rsa.pub files in it. These work when I use git in gitbash shell. I have set %HOME% to point to my home directory, but still git commands give "permission denied(public key)". Any other ideas? Note that in the gitbash shell, it is necessary to have a .bashrc that starts and ssh agent. I am wondering if this is what is missing for the windows command prompt? – GreenAsJade Sep 08 '13 at 12:30
  • @GreenAsJade yes, but do you see `%HOME%` defined though? What does a set `HOME` returns in your DOS session. If you executed `git-cmd.bat`, then `HOME` should be correctly set, and `%HOME%/.ssh` should exist. – VonC Sep 08 '13 at 12:32
  • @GreenAsJade Otherwise, classic ssh debugging: `ssh -Tvvv user@yourServer`. (http://stackoverflow.com/a/16119444/6309 and http://stackoverflow.com/a/922461/6309) – VonC Sep 08 '13 at 12:35
  • Thanks again. I have tried git-cmd.bat, the result is the same. I must be missing something really basic: I don't have ssh available at my windows prompt, so I can't say "ssh -T" (I can say this in the gitbash shell, and it works) – GreenAsJade Sep 08 '13 at 14:48
  • Hmm - I did c:\Program Files\git\bin\ssh.exe -T git@bitbucket.org and I get permission denied. I did C:\Program Files\Putty\plink.exe -T git@bitbucket.org and it works. Does this mean I need different keys somehow? – GreenAsJade Sep 08 '13 at 15:05
  • Hah ... no, obviously, it means I need to set GIT_SSH to point to plink! – GreenAsJade Sep 08 '13 at 15:09
  • 1
    @GreenAsJade sounds great. I have included your conclusion in the answer for more visibility. – VonC Sep 08 '13 at 16:02
-3

Well, maybe I have a process that seems to work.

If you use a passphrase during the generation of the keys, you'll have to type this passphrase after loading an ssh-agent and add the key to the agent.

Basically, the solution is: follow the instructions on this page:

https://confluence.atlassian.com/bitbucket/set-up-ssh-for-git-728138079.html

BUT, during the generation of the keys DO NOT TYPE A PASSPHRASE.

Obviously, it's 'weaker' from a security point of view.

But, the .bashrc script will work as expected (loading the identity on git bash startup).

You can use then the "start-ssh-agent.cmd" script located on Git\cmd folder. It will open a Dos Prompt with the identity loaded and everything will work!