If you ever used svn command line, you know it is not optimal to type in your password every time you do checkout, checkin, info, etc.Â In linux world, it is very easy to setup keys to get around this.Â Of course in the world of Windows it is not as easy.Â Â Here are the steps you need to follow to get private/public keys working with your SVN under Windows using ssh tunneling.
Assumptions:Â you will be connecting as user “root” to svn server located at “10.0.0.1”.Â All your files will be saved at c:\ including your svn command line utility
First we will have to generate a key.Â We can accomplish this by using a free utility called puttygen.Â Run puttygen and click on “Generate” button.Â You will have a key similar to below example:
Copy this, you will need it in few mins.Â At this point, go ahead and create a private key by clicking on:Â “Save private key”.Â Save this as private.ppk on your C:\.Â
Now let us log in to the svn server and add this public key to the authorized_keys2 (see setting up keys for step by step instructions).Â I will assume you are using “root” as login.
Make sure when you paste, it is not broken into different lines.Â All of the key should be one line.
Ok now back to your Windows machine.Â Now we need to set up ssh tunnel to our server.Â There are few ways of doing this but for our purpose, we will use another free program provided by the same developers as puttygen: download plink to C:\.Â If you do not do this step, you will get following error:
svn: Can't create tunnel: The system cannot find the file specified.
Ok let us set the variables for svn.Â Go to command prompt and type (you can also set this in your scripts and inside windows environment.Â But since this post is to show you an example, we will just do this):
set SVN_SSH="/plink.exe" -i /private.ppk -l root
Now let’s run this one time manually to cache key:
/plink.exe -i /private.ppk -l root 10.0.0.1
Press “y” when it asks you to save.Â Type exit and get back to your prompt.
Ok now we can test our svn utility.
/svn info svn+ssh://10.0.0.1/svn/testrepo/trunk/
This should display output similar to:
Repository Root: svn+ssh://10.0.0.1/svn/testrepo
Repository UUID: b9143312-b1a1-11ba-a111-11cdcd1d2222
Node Kind: directory
Last Changed Author: root
Last Changed Rev: 4
Last Changed Date: 2008-11-18 15:18:47 -0800 (Tue, 18 Nov 2008)
Now you are ready to script your checkouts, do checkin’s with out having to type in your password, etc.
DISCLAIMER: Please be smart and use code found on internet carefully. Make backups often. And yeah.. last but not least.. I am not responsible for any damage caused by this posting. Use at your own risk.