SnapOverflow

SnapOverflow Logo SnapOverflow Logo

SnapOverflow Navigation

  • Home
  • Server
  • Ubuntu

Mobile menu

Close
  • Home
  • System Administrators
    • Hot Questions
    • New Questions
    • Tags
  • Ubuntu
    • Hot Questions
    • New Questions
    • Tags
  • Help
Home / server / Questions / 194567
Accepted
binaryorganic
binaryorganic
Asked: 2010-10-26 08:45:39 +0800 CST2010-10-26 08:45:39 +0800 CST 2010-10-26 08:45:39 +0800 CST

How do I tell Git for Windows where to find my private RSA key?

  • 772

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.

windows ssh rsa git private-key
  • 30 30 Answers
  • 1076523 Views

30 Answers

  • Voted
  1. Best Answer
    Dan McClain
    2010-11-06T09:18:19+08:002010-11-06T09:18:19+08:00

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

    • 521
  2. Oct
    2010-11-06T10:24:53+08:002010-11-06T10:24:53+08:00

    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.

    • 115
  3. pacey
    2010-11-06T06:07:17+08:002010-11-06T06:07:17+08:00

    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.

    A screenshot is below:

    Enter image description here

    • 62
  4. Hugh Perkins
    2012-04-25T17:32:58+08:002012-04-25T17:32:58+08:00

    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.

    • 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 the public key to your server, for example: scp ~/.ssh/id_rsa.pub [email protected]:~

    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 [email protected] ls
    

    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:

    • In Git Bash, type 'cat ~/.ssh/id_rsa.pub', select the result, and copy it to the clipboard.
    • On the GitHub website, go to 'Account settings', 'SSH and GPG keys', click 'New SSH key', and paste the key.
    • 56
  5. GregB
    2013-04-11T22:34:29+08:002013-04-11T22:34:29+08:00

    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:

    Host bitbucket.org
        Hostname bitbucket.org
        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
    
    • 53
  6. Jono
    2012-10-12T17:26:17+08:002012-10-12T17:26:17+08:00

    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
    • 17
  7. oglop
    2017-11-03T07:27:47+08:002017-11-03T07:27:47+08:00

    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:

    Host example.com
       Identityfile ~/.ssh/id_rsa
    

    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 from stdout of keyscan (on Windows) changes encoding to UCS-2, but OpenSSH can read only UTF-8! So make sure to change the known_hosts file encoding.

    • 11
  8. Declan Shanaghy
    2010-10-26T09:38:09+08:002010-10-26T09:38:09+08:00

    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

    • 7
  9. IDisposable
    2014-09-05T14:34:49+08:002014-09-05T14:34:49+08:00

    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:

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

    Change it to:

    [remote "origin"]
        url = [email protected]:**username**/**reponame**.git
        fetch = +refs/heads/*:refs/remotes/origin/*
    
    • 5
  10. knocte
    2017-05-16T02:57:02+08:002017-05-16T02:57:02+08:00

    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:

    1. Download pageant.exe, puttygen.exe, putty.exe and plink.exe from PuTTY's website. Place them in C:\puttyTools directory.
    2. Run puttygen.exe.
    3. Click button Generate.
    4. Wiggle the mouse around in the top part of the window until the progress bar is full, as the program asks you to do.
    5. Provide a passphrase, and repeat it in the subsequent textbox.
    6. Click "Save private key". The usual directory to save these in is %USERPROFILE%\.ssh (in my computer this maps to C:\Users\andres\.ssh\). It doesn't matter what you call the key, but for demonstration purposes, I'm going to call it github.ppk. This file should have an extension of .ppk.
    7. Copy the text in the top text box in PuTTYgen, the one labeled 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").
    8. Run pageant.exe, a new systray icon will appear.
    9. Right click on the icon -> Add key.
    10. Locate your ppk file, enter your passphrase.
    11. Create these new user environment variables (via looking for application Environ through WindowsMenu which will find Edit environment variables for your account): GIT_SSH = "C:\puttyTools\plink.exe" and SVN_SSH = "C:\puttyTools\PuTTY\plink.exe"
    12. Open putty.exe and try to connect to the host where you host your Git repositories. For example, try to connect to github.com via SSH, and a dialog will ask you if you accept the fingerprint of the server: click on YES.
    13. Run a new instance of your MINGW64 Git console, and verify that the environment variables are there by writing the command env | grep -i ssh.
    14. You should be all set. Try to clone with the Git + SSH protocol from your host.

    (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.)

    • 5

Sidebar

Stats

  • Questions 681965
  • Answers 980273
  • Best Answers 280204
  • Users 287326
  • Popular
  • Answers
  • Marko Smith

    Ping a Specific Port

    • 18 Answers
  • Marko Smith

    How do I tell Git for Windows where to find my private RSA key?

    • 30 Answers
  • Marko Smith

    How do you restart php-fpm?

    • 18 Answers
  • Marko Smith

    What's the default superuser username/password for postgres after a new install?

    • 5 Answers
  • Marko Smith

    What port does SFTP use?

    • 6 Answers
  • Marko Smith

    Resolve host name from IP address

    • 8 Answers
  • Marko Smith

    How can I sort du -h output by size

    • 30 Answers
  • Marko Smith

    Command line to list users in a Windows Active Directory group?

    • 9 Answers
  • Marko Smith

    What is a Pem file and how does it differ from other OpenSSL Generated Key File Formats?

    • 3 Answers
  • Marko Smith

    How to determine if a bash variable is empty?

    • 15 Answers
  • Martin Hope
    Davie Ping a Specific Port 2009-10-09 01:57:50 +0800 CST
  • Martin Hope
    binaryorganic How do I tell Git for Windows where to find my private RSA key? 2010-10-26 08:45:39 +0800 CST
  • Martin Hope
    tobym What exactly do the colors in htop status bars mean? 2010-09-14 12:22:43 +0800 CST
  • Martin Hope
    MikeN In Nginx, how can I rewrite all http requests to https while maintaining sub-domain? 2009-09-22 06:04:43 +0800 CST
  • Martin Hope
    Tom Feiner How can I sort du -h output by size 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    0x89 What is the difference between double and single square brackets in bash? 2009-08-10 13:11:51 +0800 CST
  • Martin Hope
    Kyle Brandt How does IPv4 Subnetting Work? 2009-08-05 06:05:31 +0800 CST
  • Martin Hope
    Noah Goodrich What is a Pem file and how does it differ from other OpenSSL Generated Key File Formats? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent How to determine if a bash variable is empty? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus How do you find what process is holding a file open in Windows? 2009-05-01 16:47:16 +0800 CST

Related Questions

Trending Tags

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • Home
  • Questions
    • Hot Questions
    • New Questions
  • Tags
  • Help

Footer

SnapOverflow

About Us

  • About Us
  • Contact Us

Legal Stuff

  • Privacy Policy

Help

© 2022 SOF-TR. All Rights Reserve