Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My GIT setup runs fine in 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.

share|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

23 Answers 23

up vote 310 down vote accepted

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.

Note: Comments indicate that this doesn't work in all cases. You may need to copy the OpenSSH key to Program Files\Git\.ssh\id_rsa (or Program Files (x86)\Git\.ssh\id_rsa).

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

share|improve this answer
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 '12 at 12:17
Likewise. I just installed git-for-windows, I am running it from cmd.exe. I needed to put the files id_rsa and into c:\program files (x86)\Git\.ssh . The .ssh dir was already present. Thanks, JP. – Cheeso Jul 26 '12 at 1:07
Second paragraph was golden. :) – Bjørn Aug 31 '12 at 10:51
@Damon: It should be id_rsa without the extension. That is the file name, it is not a directory – Dan McClain Nov 27 '12 at 13:26

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

For example, on a Windows Vista installation, this would be done by issuing setx HOME c:\Users\admin\ on the command line.

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. Refer to all the svn+ssh tutorials, this is basically the same plumbing you need to setup.

share|improve this answer
This is what I was looking for since I'm trying to use the Windows command prompt, not git bash. – John Ruiz Mar 5 '12 at 18:33
Nice, easy fix but it would have been hard to figure out without this! – thaddeusmt Apr 13 '12 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 '12 at 23:09
Worth noting - if you have spaces in your home (if you are using win XP/server 2003 you will), then you should prefix the path with a single quote. Bizarrely - if you end it with a quote that will be in the variable... – Danny Staple Apr 16 '13 at 10:57
The setx HOME c:\Users\admin` command doesn't seems to be working in Git Bash. You have to use cmd` instead. – trejder Dec 12 '13 at 8:01

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

share|improve this answer
Additionally if you need to convert your private key into '.ppk' format from other format you can follow THIS – HeartBeat Dec 18 '13 at 11:04
It worked for me. – Maxim Eliseev Sep 10 '14 at 16:53
Thanks @pacey . This saved my day. – adrian7 Sep 27 '14 at 20:17
Git > Remote only appears once you've successfully cloned the repository. – Steve Pitchers Jul 23 '15 at 9:18
A much easier solution is to set everything up working properly in git (using openSSH), and then tell TortoiseGit to use the ssh.exe used by git. See That way, you only need to fix this once. – Daniel Rose Feb 4 at 16:04

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/

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

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

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

ssh ls

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

Edit: for github, you dont have shell access to their server, but you can upload the key using their website, so for the bit 'now copy to your server', do:

  • in git bash, type 'cat ~/.ssh/', select the result, and copy it to the clipboard
  • In github website, go to 'account settings', 'ssh keys', click 'add ssh key', and paste the key
share|improve this answer
Don't create keys without passphrases. It's like putting your password in a text file, except that everyone knows the default location for private keys. – GregB Apr 11 '13 at 6:10
You're answering the wrong question. The Q is how to point to an existing private key. – Scandalon Apr 17 '13 at 18:18
@GregB, I look at it like this: any server for which I create a password-less key is as secure as my laptop, it's an extension of the security perimeter of my laptop. Actually, not even, since my home directory is encrypted ;-) So, it's as secure as the encrypted home partition on my laptop, which is 'good enough' for securing access to github, in my opinion. (which may vary from your opinion of course!) – Hugh Perkins Jun 21 '13 at 5:38
@GregB Don't fall down into paranoia! :] Sure, that using password-protected keys is much more secure, than using password-less, but claiming that password-less key is as easy to break as storing passwords in a text file is an obvious false. I've seen many guides, that encourage users to use password-protected keys, but I have never seen any claiming, that using them without passwords is not secure at all. Plus: some systems doesn't support solutions for remembering key's password, entered by users, and asks for it, each time key is used. Which makes using SSH keys pointless in this situation. – trejder Dec 12 '13 at 8:33
For the sake of the conversation, which has deviated from the original question, SSH keys are certainly more cryptographically secure than passwords, but that security is put at risk by not encrypting your SSH keys. My personal approach is to unlock my keys at the beginning of the day using an SSH agent, which then keeps the decrypted keys in memory so that I don't need to re-enter the password throughout the day. As @Hugh Perkins comments, and I'm paraphrasing, you all know your security requirements better than I/we do :). – GregB Dec 13 '13 at 18:09

If you're using msysgit with the OpenSSH tools, you need to either create ~/.ssh/id_rsa, or create a git config in ~/.ssh/config which points to your key.

Here's an example of a Git config for bitbucket that will use the correct username, and a key other than the default key (in case you maintain one key for SSH connections, and another for git accounts).

    User git
    IdentityFile /C/keys/yourkey.key

Once in git bash, you can run two commands to add your key to your current session's ssh-agent to avoid having to repeatedly type the key's password.

eval `ssh-agent`
ssh-add /C/keys/yourkey.key
share|improve this answer
I did this but for Host IdentityFile ~/.ssh/github_rsa – Sarah Vessels Jun 22 '13 at 18:28
If you have a space in your path you have to use quotes: IdentityFile "/C/My Keys/key" – r03 Aug 1 '14 at 10:31

I just set %HOME%=%HOMEPATH%

This has the advantage of working for all users logged into the system (they each get separate .ssh folders).

In Vista:

  1. Right-click on Computer
  2. Choose Properties
  3. Click on Advanced System Settings
  4. Click on Environment Variables
  5. In the bottom section (System Variables) Click on New
  6. For Variable name type: HOME
  7. For Variable path type: %HOMEPATH%
  8. Click OK
share|improve this answer
In my case I've added HOME = %USERPROFILE% – igor Oct 14 '13 at 11:41
Note that %HOMEPATH% does not contain the drive letter, so if your source is not on C: you need to prepend C: to %HOME%. – Graeme Perrow Mar 2 at 12:36

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 (pageant) might do the trick for you, here's the link to the official binaries and source:

share|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
Pageant does indeed solve the problem for me -- I have a shortcut in my Start Menu's Startup folder (C:\Users\owen.blacker\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup) pointing to "C:\Program Files (x86)\PuTTY\pageant.exe" "C:\Users\owen.blacker\Documents\SSH\OwenBlackerPersonal.ppk" "C:\Users\owen.blacker\Documents\SSH\OwenBlackerWork.ppk", so that it loads my SSH keys on startup and this makes GIT "just work" :o) – Owen Blacker Jun 27 '12 at 12:51
@OwenBlacker OMFG! You definitely should write this comment as a full-size answer! This is the only solution here, that actually helped me and solved my problem! Pity, that I can give you only +1! :] – trejder Dec 12 '13 at 9:01

Oke, i lookt at the sugestion of

But placeing in my private ssh keys in public folder i didn't was good idea so i started to look where are is the knownhost.

So if you want to correctly protect your ssh key you need to put your key in the following directory for Windows 7,8 and 8.1 32-bit in

C:\Users\\AppData\Local\VirtualStore\Program Files\Git\

for Windows 7,8 and 8.1 64-bit in

C:\Users\\AppData\Local\VirtualStore\Program Files (x86)\Git\

I hope this help some of you

share|improve this answer
Hi Bas. I think you should delete your question and ask or give it on Super User because this is the wrong site for this sort of question / answer :-) – Ian Macintosh Sep 8 '14 at 10:32
It not quistion of me just sugestion – Bas van den Dikkenberg Sep 10 '14 at 16:03
This was the simplest solution on my Win7 machine. Like you, I searched for known_hosts. Sure enough, it was in C:\Users\Dave\AppData\Local\VirtualStore\Program Files (x86)\Git\.ssh. By placing my key file (id_rsa) in that directory, ssh was able to find it without complaint. I did a little reading - this is how Windows handles (legacy) software attempting to write to forbidden areas (such as "C:\Program Files\"), so Git's ssh is completely unaware that it is writing to the VirtualStore directory, Windows is handling that transparently. At least these files belong to a user! – DaveGauer Apr 29 '15 at 23:40

The following answer also applies to this question when running ssh from Windows Service Account: Jenkins (Windows Service) with Git over SSH

share|improve this answer
Following the link you provided I was able to get my Jenkins setup. I needed to set the HOME environment variable to the Git program path which held the .ssh directory I created my SSH key in. – Spechal Sep 3 '13 at 18:52

You can specify both path to key and name of key file like so (on ubuntu). For example:

ssh -i /home/joe/.ssh/eui_rsa
share|improve this answer
This absolutely solves the problem and allows you to store your keys where ever you would like. – DaveGauer Apr 29 '15 at 23:26

I originally posted this as a comment, but someone suggested I should post it as a proper answer.

Pageant (an SSH agent supplied with the PuTTY bundle) solves the problem for me.

I have a shortcut in my Start Menu's Startup folder (C:\Users\owen.blacker\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup) pointing to "C:\Program Files (x86)\PuTTY\pageant.exe" "C:\Users\owen.blacker\Documents\SSH\OwenBlackerPersonal.ppk" "C:\Users\owen.blacker\Documents\SSH\OwenBlackerWork.ppk", so that it loads my SSH keys on startup and this makes GIT "just work" :o)

share|improve this answer
I think you need several other settings correct for this to work (such as GIT_SSH set to TortoisePLink.exe I think?), and although it has worked for me in the past, I often get problems with it on other machines. :-( – Simon East Jun 12 '14 at 4:08

When mixing GitHub for Windows and Git GUI for windows, you might run into issues where Git GUI keeps prompting you for a username and password. The cure for this is to change the remote url from https: (which is what GitHub for Windows creates) to git protocol. In the .git directory in the config file find

[remote "origin"]
   url =**username**/**reponame**.git
   fetch = +refs/heads/*:refs/remotes/origin/*

change to

[remote "origin"]
    url =**username**/**reponame**.git
    fetch = +refs/heads/*:refs/remotes/origin/*
share|improve this answer
Yeah it is very annoying. It is natural and easy to clone a repo with github for windows GUI, but when use git cui outside of git shell failed. I wonder how the git command in the git shell works with https url... – hiroshi Mar 5 at 1:18
for SSH is the prefix always git@{SERVER URL} ? – nmz787 Apr 15 at 20:41
Yes, as far as I've ever seen :) – IDisposable Apr 19 at 4:11

I had similar issues and none of the answers here solved the problem. Turns out, my key pair were originally generated with an empty passphrase. (I know, dumb)

Once I created a new keypair and uploaded the public key to github, things started working again.

share|improve this answer
this. ughhhhhhhhhhhhh. good bye 2 hours – Scoop Feb 5 '15 at 10:36

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!

share|improve this answer

Using Git Gui on Windows v0.17 I clicked on the following menu commands

Help > Show SSH Key

A dialog appeared entitled Your OpenSSH Public Key. I generated a key and copied it to the clipboard. Then I continued to follow the setup-ssh instructions on githelp from Step Three onwards. Afterwards Git Gui communicated with Github silently - no need to enter any credentials.

share|improve this answer

On my windows 7 system GitGui looks for the RSA key in the userprofile/.ssh folder or more specifically c:/users/yourusername/.ssh/

The tricky part for my setup was getting the shared host at hostmonster to accept the key. The only way I could get it to work was by using GitGui to create the key pairs (without a password) and then copy and pasting the public key via the control panel, ssh, manage keys.

To start at the beginning you have to create the keys in GitGui by going to Help, Show SSH key, then Generate Key. Now you will have two new keys in the .ssh directory. Open the .pub file and copy the contents. Log in to your control panel on shared host and go into ssh, manage ssh keys, import key. Paste into the Public box, and make sure you name it the right name without the extension-- mine was id_rsa. Now you must authorize the key using the manage authorization link, so it will get concatenated into the authorized_keys file.

Now your GitGui and your GitBash should be able to push using ssh without having to type the password. Oddly, I was able to push using ssh via git bash and git gui just fine on my own servers running linux, it was just the shared hosting that was giving me fits. Hope this helps someone as it took me hours of trial and error to come up with this--and its so simple!

share|improve this answer

If you're on Windows 7/8, you should look in C:\Users\Your_User_Name.ssh Just copy & paste your id_rsa file here and it will all work out-of-the-box.

share|improve this answer

The standard location for the files is in %USERPROFILE%\.ssh

%USERPROFILE% is the equivalent of $HOME in Unix. (normally maps to something like c:\users\youruserid)

If you are using the ssh tools that came with git, which are the standard command line unix-style tools, you can use something like my script here to work with ssh-agent across all shells.

share|improve this answer

If you are using Git command line for Windows you can do as following:

Open cmd.exe and execute setx HOME c:\PATH_TO_PRIVATE_KEY

Create new folder .ssh (if not exist) inside c:\PATH_TO_PRIVATE_KEY and copy your id_rsa file (your private key) into it.

Done, now you can use git commanline normally

share|improve this answer

One mistake I made when using SSH on Windows was that when I attempted to use the keys through the Git Bash client, all of the files within ~/.ssh were the wrong permissions, yet it did not attempt to tell me that it was a problem.

Just as a test, make sure you've set everything in your ~/.ssh directory to chmod 600.

share|improve this answer

My msysgit OpenSSL/Bash GIT experience (not Putty's plink) is that the search order for your the .ssh/ folder is as follows.

  1. %HOME%/.ssh/
  3. %USERPROFILE%/.ssh/

Hence why so many people suggest setting HOME if one of the others is not what you expect. More importantly you can check for yourself, to debug use ssh -v to a server that uses publickey authentication as follows:

$ ssh -v
OpenSSH_4.6p1, OpenSSL 0.9.8e 23 Feb 2007
debug1: Reading configuration data /d/.ssh/config
debug1: identity file /d/.ssh/identity type -1
debug1: identity file /d/.ssh/id_rsa type 1
debug1: identity file /d/.ssh/id_dsa type -1
debug1: Next authentication method: publickey
debug1: Trying private key: /d/.ssh/identity
debug1: Offering public key: /d/.ssh/id_rsa
Hi kcd83! You've successfully authenticated, but GitHub does not provide shell access.

Sorry for adding yet another answer but we found ssh searching in an obscure drive and none of the answers seemed to explain what we saw.

share|improve this answer

If you have the necessary permissions on the Windows machine, and your policies permit it, I would suggest installing Cygwin (, especially considering that you have prior experience with Linux. Cygwin will make it possible to handle your ssh-keys as you would on any other Linux/Unix machine. And it provides access to almost all of the cli tools of Linux.

share|improve this answer

You can also load Putty Agent (pageant) and add the private key you generated with Putty for the server.

Git recognizes this and uses that for push/pull.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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