TortoiseSVN and SSH non-standard port

TortoiseSVN and SSH non-standard port

I came across the need to use TortoiseSVN on Windows 7. GNU/Linux hosted our SVN repository and we accessed it with SSH (svn+ssh://). SSH ran on a non-standard port of 55000. Here’s how I got TortoiseSVN and SSH non-standard port to work.

Requirements

  • SSH account
    It is assumed that you have an account on GNU/Linux server and you can successfully SSH into the system using PuTTY or similar software. Let’s say your SSH account was named svnaccount on server named myserver, and this server hosts the repository under /home/svnaccount/myproject
  • PuTTY
    We will use this software to SSH into your account initial and test what we need.
  • PuTTYgen
    We will generate a public and private key using this software and then configure SSH to do a password-less login.
  • PSCP
    We will use this software to copy the public key over to the server.
  • TortoiseSVN
    It’s installation directory is assumed to be c:\program files\tortoisesvn. Let’s say we want to checkout our code under c:\mycode\ directory
  • TortoisePlink.exe
    It is assumed to be located under c:\program files\tortoisesvn\bin. This software will be used as a command line interface to PuTTY. Instead of using PuTTY and manually log in, we will use this software to log on to the server using password-less login.
  • Pageant
    This tool will be used to do SSH authentication for TortoisePlink.exe.

Generate public/private keys

Open PuTTYgen and click Generate button. Then, move your mouse in the blank area underneath the progress bar.

puttygen-1

Once the key is generated, copy the public key. Open Notepad and paste the public key. Then, save the file as c:\myserver-pub.txt.

puttygen-2

Also click on Save public key and save it under c:\myserver-public-key.txt. Then, click Save private key and save the key under c:\myserver-private-key.ppk

Configure password-less login

Open cmd.exe. Then, copy myserver-pub.txt over to the server

C:\Users\Tester> c:\SCP.exe -P 55000 c:\myserver-pub.txt [email protected]:/home/svnaccount/myserver-pub.txt
[email protected]'s Password: 
myserver-pub.txt      | 2 kB |   2.2 kB/s | ETA: 00:00:00 | 100%
C:\Users\Tester>

After that, use PuTTY to log on to the server

putty-1

If .ssh directory does not exist, create .ssh directory using mkdir .ssh. Append contents of myserver-pub.txt to .ssh/authorized_keys2.

[email protected] /home/svnaccount> mkdir .ssh
[email protected] /home/svnaccount> cat myserver-pub.txt >> .ssh/authorized_keys2
[email protected] /home/svnaccount>

Note: Your public key can be copied in an easier manner by doing something like this (reference: http://support.suso.com/supki/SSH_Tutorial_for_Linux):

ssh-copy-id [email protected]

Exit PuTTY and open PuTTY again. Thereafter, enter the hostname, the port and ensure that connection type is set to SSH. Then, in the left menu, expand Connection if necessary. Click on Data. Type in your account in auto-login username.

putty-2

In the menu, under Connection, expand SSH and click on Auth. Then, click on Browse and choose the private file c:\myserver-private.ppk.

putty-3

Click on Session in the menu to the left, give these settings a name and save it. Open the connection and now you should be logged in without the need for a password.

TortoiseSVN configuration file

Under c:\Users\<your username>\AppData\Roaming\Subversion will be a config file. Open the config file in an editor like Notepad++. Notice a section called [tunnels]. At the end of that section add the following line and save the file.

myssh = c:\\Program Files\\TortoiseSVN\\bin\\TortoisePlink.exe -P 55000

Notice that TortoiseSVN wants backslashes escaped. You may choose to use a single forward-slash instead of two backslashes.

NOTE: If you do not want to run pageant.exe, you could change the above line to

myssh = c:\\Program Files\\TortoiseSVN\\bin\\TortoisePlink.exe -P 55000 -i c:\\myserver-private.ppk

Instead of connecting to the server manually with PuTTY, we will let TortoisePlink.exe log on to the server just like we did above. In order for TortoisePlink.exe to succeed, it needs a port number. We provided it a port number and gave that entire command a name called myssh. Unlike PuTTY, we have not yet given TortoisePlink.exe any instruction to use our private key.

Start Pageant

Double click pageant.exe. It will begin running and make itself accessible in the system tray. Double click the pageant icon and click Add Key and choose c:\myserver-private.ppk file. An excerpt of the private key will show up in Pageant.

pageant-1

Keep pageant running. If you do not want to run pageant, check out the NOTE in the above section.

Subversion/TortoiseSVN

Explore to c:\mycode directory.

svn-1

Right click into an empty area of Explorer and click TortoiseSVN — Settings. Then, in the Settings dialog, click on Network. In the SSH box, type in c:\Program Files\TortoiseSVN\bin\TortoisePlink.exe -P 55000. Finally, notice that there are no quotations.

svn-2

 

Then, OK out of the settings. Following that, right click an empty area of Explorer and click TortoiseSVN — Import. In the URL type in svn+myssh://svnaccount@myserver/home/svnaccount/myrepo and click OK. The import should be successful. Following that, do TortoiseSVN — Checkout to get your code.

svn-3

 

This works because the URL starts with svn+myssh://. This tells TortoiseSVN to look for a tunnel named myssh. A a result, the tunnel indicates that we can use TortoisePlink and port 55000. The URL’s [email protected] tells TortoiseSVN to inform TortoisePlink to access myserver.com with svnaccount username. But how should we log on? TortoisePlink checks to see if Pageant is running and if it has a key loaded. We are running Pageant. We have loaded the private key in it. TortoisePlink uses svnaccount username and the private key to authenticate against myserver’s SSH server. The /home/svnaccount/myrepo tells TortoiseSVN to import information about repo located in a particular directory. And that is all. You have access to your code now.

Can we use standard port with this method also? Yes. Instead of using port 55000, use port 22 (default SSH port) or just remove -P 55000. Additionally, check out mono-project’s article about PuTTY and TortoiseSVN which gave me the motivation to write up this article.