My GIT setup runs fine within linux, but when I try to set things up under Windows (using git for windows and tortoisegit) I don't know where to put my private ssh key (or, better still, how to tell ssh where it's located). I'm using the standard ssh.exe option during installation of git for windows. The setup runs fine if I allow password authentication (in lieu of rsa) on the server.

link|improve this question

I have the same problem, I can ssh into my dev box using a public key as "root" using the "Git Bash" program that is installed with "Git For Windows" but I can't log in as "git" with my key even though I have copied my "authorized_keys" file from my "root" to my "git" user and set the owners and permissions correctly. Why can't I login as "git" when "root" works with the exact same "authorized_keys" file. Instead for "git" it passes up all the private keys, which are the exact same that work with "root" and asks for a password. This is a Centos 5.5 server by the way. – Jarrod Roberson Nov 5 '10 at 1:36
@fuzzy lollipop: Do you have the right permissions on your git user's authorized_keys file? It should be chmod 600, and should be owned by the git user. If it's owned by the root user, it wont work – Dan McClain Nov 5 '10 at 17:20
yes all the files and directories are the correct owners and permissions – Jarrod Roberson Nov 6 '10 at 7:21
feedback

9 Answers

up vote 28 down vote accepted
+25

For Git Bash

If you are running msysgit (I am assuming you are) and are looking to run Git Bash (I recommend it over TortoiseGit, but I lean to the CLI more than GUI now), you need to figure out what your home directory is for Git Bash by starting it then type pwd (On Win7, it will be something like C:\Users\phsr I think). While you're in git bash, you should mkdir .ssh.

After you have the home directory, and a .ssh folder under that, you want to open PuTTYgen and open the key (.ppk file) you have previously created. Once your key is open, you want to select Conversions -> Export OpenSSH key and save it to HOME\.ssh\id_rsa. After you have the key at that location, Git bash will recognize the key and use it

For TortoiseGit

When using TortoiseGit, you need to set the SSH key via pacey's directions. You need to do that for every repository you are using TortoiseGit with

link|improve this answer
1  
pacey's instructions for tortoisegit won't work until you have the repository (because the 'remote' configuration setting doesn't appear unless you act on a repo), and you probably can't get the repository in the first place if you can't authenticate yourself in order to clone from the origin. Tricky! – Kylotan Oct 6 '11 at 19:59
With GitBash I found I had to copy my ~/.ssh/id_rsa file to Program Files\Git\.ssh\id_rsa - which was a little confusing, but now IntelliJ and Windows cmd can push to git repositories that use key authentication. – JP. May 23 at 12:17
feedback

Using the built-in SSH client shipped with Git for windows, you need to setup the HOME environment variable correctly so that the Git SSH client can find the key.

For example on a Windows Vista OS,

set HOME=c:\Users\admin\

Made my day and fixed the issue with Git provided that your private key is not password protected. If you want to use ssh-agent, then you can probably run ssh-agent cmd.exe (although I've never done that) and the ssh-add as usual.

Note that all Git/SSH tools are supposed to be run from a cmd.exe in order not to blink a window.

If this does not work correctly, using plink can probably be achieved by tweaking GIT_SSH. Confer to all the svn+ssh tutorials, this is basically the same plumbing you need to setup.

Good Luck !

link|improve this answer
1  
This is what I was looking for since I'm trying to use the Windows command prompt, not git bash. – John Ruiz Mar 5 at 18:33
Nice, easy fix but it would have been hard to figure out without this! – thaddeusmt Apr 13 at 20:39
Important is as well to have no blanks between HOME = and c:\... Oct's solution did the trick for me. :-) – Lutz Apr 21 at 23:09
feedback

Your private key needs to be added to the SSH agent on your workstation. How you achieve this may depend on what git client you are using, however puTTY and its associated agent (pagent) might do the trick for you

http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

link|improve this answer
I stated above that I'm using Git for Windows and am using ssh.exe (packaged w/ git) in lieu of putty. There must be some standard practice for adding a private key, I just can't seem to find out how. While switching software may indeed allow me to log in, there has to be a way to do it with the standard Git setup, no? – binaryorganic Oct 25 '10 at 21:32
Sorry i dont work on windows, only linux. But the key does have to be in your SSH agent. is there an agent.exe or something along those lines? – Declan Shanaghy Oct 25 '10 at 22:01
Yeah, setup was cake on the linux side. But I've got to have it working on Windows too unfortunately. There are several ssh-related executable files in the git/bin folder on the Windows box (ssh, ssh-add, ssh-agent, ssh-keygen & ssh-keyscan), but I don't know how to make any of them do anything. They just blink a cmd window open and close right away. I'm stumped. – binaryorganic Oct 26 '10 at 1:13
feedback

You can specify the Key Location for Tortoisegit the following way:

  • Open an Explorer Window.
  • Open the Contextmenu and Navigate TortoiseGit > Settings
  • In the now opened window Navigate to Git > Remote
  • Set the Path to your Putty Key in the corresponding Input Box.

Screen shoot below:

enter image description here

link|improve this answer
There is no screenshot :( – AntonioCS Feb 19 at 23:05
This is the correct url: dbanck.de/static/images/091008_10_full.png – dbanck Feb 27 at 15:23
feedback

The problem was that the gitorious process was owned by root:root and not the git:git process, so it was not inheriting the in-correct permissions for the gitorious process it self and it could not find the repositories. Once I set all the gitorious related scripts in /etc/init.d to be owned by git:git I got a better error message and was able to proceed.

link|improve this answer
feedback

None of the answers above worked for me. Here was what worked for me in the end. It is actually fairly simple, if you know what to type. It doesn't need putty.

  • open a git bash prompt
  • type 'ssh-keygen'
    • accept the default location
    • choose a blank passphrase (so just press 'enter' to all questions')
  • now copy to your server, eg: scp ~/.ssh/id_rsa.pub someuser@someserver.com:~

That's the bit on your own computer done. Now ssh into the destination server, then do

mkdir -p ~/.ssh
cd ~/.ssh
cat ../id_rsa.pub >> authorized_keys
rm ../id_rsa.pub

That's it! You're done! From git bash, do the following to test:

ssh someuser@someserver.com ls

If it lists the files in your home directory on the git server, then you're done!

link|improve this answer
feedback

Reading your comment to Declan's answer, try opening a command prompt first (Start -> Run -> cmd) and then navigate to that git/bin folder and run ssh-keygen. Theoretically that will generate an RSA key and place it in the appropriate directory. Then you just gotta find it and share your public key with the world.

The reason that the window "blinks" is because windows run's the program, and when it executes, it closes the command prompt, thinking you're done with it, when you really need the output.

Hope that helps!

link|improve this answer
feedback

There is a great guide to git for windows here that shows how to integrate putty and pagent for managing your keys.

link|improve this answer
feedback

You can specify both path to key and name of key file like so (on ubuntu). ssh -i /home/joe/.ssh/eui_rsa

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.