My Git setup runs fine on 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.
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 Windows 7, it will be something likeC:\Users\phsr
I think). While you're in Git Bash, you shouldmkdir .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 selectConversions -> Export OpenSSH key
and save it toHOME\.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
(orProgram 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.
Using the built-in SSH client shipped with Git for Windows, you need to set up 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.It 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.
You can specify the key location for TortoiseGit the following way:
A screenshot is below:
None of the previous answers 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.
That's the bit on your own computer done. Now
ssh
into the destination server, then doThat's it! You're done! From Git Bash, do the following to test:
If it lists the files in your home directory on the Git server, and then you're done!
For GitHub, you don't 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:
If you're using msysgit with the OpenSSH tools, you need to either create
~/.ssh/id_rsa
, or create a Git configuration in~/.ssh/config
which points to your key.Here's an example of a Git configuration 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).
~/.ssh/config:
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.
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:
In my case I was using Git for Windows in the Docker container
windowsservercore
.My Git was installed by Chocolatey to
C:\Program Files\Git
.I had to update the file
C:\Program Files\Git\etc\ssh\ssh_config
with this:Then I was could use key from
C:\Users\<user>\.ssh\id_rsa
If you are using Git for windows together with OpenSSH for Windows. Git is still using its own
ssh
.Plus if you plan using
ssh-keyscan host.com > known_hosts
from OpenSSH, be careful because piping output fromstdout
ofkeyscan
(on Windows) changes encoding to UCS-2, but OpenSSH can read only UTF-8! So make sure to change theknown_hosts
file encoding.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:
http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
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 the Git protocol. In the.git
directory in the configuration file, find:Change it to:
The most efficient way is using Pageant because it will let you write the passphrase only once at the beginning of the session instead of every push. All answers here were too short, so I'll post a detailed guide here:
pageant.exe
,puttygen.exe
,putty.exe
andplink.exe
from PuTTY's website. Place them inC:\puttyTools
directory.puttygen.exe
.%USERPROFILE%\.ssh
(in my computer this maps toC:\Users\andres\.ssh\
). It doesn't matter what you call the key, but for demonstration purposes, I'm going to call itgithub.ppk
. This file should have an extension of .ppk.Public key for pasting into OpenSSH authorized_keys file
and paste it into a new SSH key in GitHub's settings. Give it a title that describes what machine the key is on (e.g. "Work laptop").pageant.exe
, a new systray icon will appear.Environ
through WindowsMenu which will findEdit environment variables for your account
):GIT_SSH = "C:\puttyTools\plink.exe"
andSVN_SSH = "C:\puttyTools\PuTTY\plink.exe"
MINGW64
Git console, and verify that the environment variables are there by writing the commandenv | grep -i ssh
.(Originally extracted from these two guides which I combined in one: How to setup Git for Windows and Configure MinGW-W64+MSYS to use PuTTY Plink/Pageant.)