Tuesday, December 17, 2013

Configure TortoiseGIT with RSA Private Key on Windows

If you are looking for an easy to use GUI for git then TortoiseGIT is the best I think.

  1. Download and install git for windows
  2. Open git bash and generate a RSA key-pair from git bash:
    ssh-keygen.exe -t rsa
    the key-pair will be generated in the default location (C:\Users\[user_name]\.ssh\), you can specify any other location if you wish to.
    You can also specify a passphrase/password for this key before generating the key which you will have to enter while accessing any git repository using this key.

  3. Upload/send your public key (id_rsa.pub) file to the administrator of your git-server.
    Once this public key is added in the server, you can access permitted repositories on git-server from your PC using git.
  4. Configure your name and email address for git:
    git config --global user.name "Your Name"
    git config --global user.email "your@mail.address"
    

    These information will be used to identify you when you perform operations (commit/push) on git repositories.
  5. clone a repository ('my_repo') from the server.
    git clone git@your_git_server_name_or_ip:my_repo
    You will be asked for a passphrase for your rsa key (if you had specified one during key generation) and 'my_repo' will be created in the current directory.
  6. Download and install TortoiseGIT.
  7. Now you have to show TortoiseGIT your private key file. But, TortoiseGIT doesn't recognize private key file unless the file is in '.ppk' format. So, you need to generate a '.ppk' private key form your existing private key ('id_rsa' that was generated in step 2).
  8. Download puTTYgen.exe and run it (No installation required).
    Go to 'Conversions-->Import Key' and select your private key ('id_rsa') file. You will be asked for the passphrase for your rsa key (if you had specified one during key generation).


    'Save private key' in '.ppk' format somewhere.
    Close puTTYgen.
  9. Once you have the private key in '.ppk' format, the repository can also be cloned using TortoiseGIT rather than the command line approach described in step 5. Right click on the folder where you want to clone the repository and click on 'Git clone...'. Then enter the repository url, check 'Load putty key' checkbox and enter the location of the private key ('.ppk' format). Click 'Ok'. The repository ('my_repo') will be created.
  10. Click on 'my_repo' which was cloned in step 5 or 9, open 'TortoiseGIT-->Settings-->Git-->Remote', select origin, select the location of your '.ppk' private key file in the "Putty Key" box and click "Apply" then "Ok".

  11. Now TortoiseGIT is ready to fetch/pull/push on git using your private key. You can check it: right click on 'my_repo', then select "TortoiseGIT-->Fetch". You may be asked to enter the passphrase for your key again.

View the screenshots for TortoiseGIT to get better idea on how to use it.


Important links Related to this post:

4 comments:

  1. What the sense of this .ppk key as TortoiseGit always asks for passphrase? Is there a way to remember it? Also "Load Putty Key" check box is disableb for me when cloning.

    ReplyDelete
    Replies
    1. TortoiseGit normally remembers the key. In my case, the pass-phrase is asked only once each time I start my PC.

      Delete
    2. In my case it is not - asks every time I push/pull.

      Delete
  2. Ha, above works if set SSH client back to tortoisegitplink.

    ReplyDelete