Setting up a subversion server

This article shows how to set up a subversion server that will allow local and remote access.

In this article we’ll set up a subversion server that will allow remote access. We will use Ubuntu, but the process isn’t that different if you are using a different distro.

First of all install the subversion package. In ubuntu thats:

sudo apt-get install subversion

Create a directory where you will store the subversion repositories. (we use /var/repos in this example.) Then, add a user for the svn (we’ll use the username svn), and give it ownership of the repos directory.

sudo mkdir /var/repos
sudo adduser --system --home /var/repos --no-create-home --disabled-password --disabled-login --group svn
sudo chown -R svn:svn /var/repos

As the new user, create a new svn repository:

sudo -s -u svn
svnadmin create /var/repos/myrepo
exit

At this point you should have a basic subversion server which you can run from the command line:

svnserve -d --foreground -r /var/repos

It should start running and stay in the foreground in the console (though it doesn’t output anything to the console). You now have a subversion server running on that host, listening on port 3690, which is the default svnserve port.

From another console, or better yet a console in another computer in the network that has a subversion client installed, try:

svn ls svn://<hostname>/myrepo/

… replacing <hostname> with the actual hostname for the computer running subversion.

Since we are listing an empty repository, this should exit without printing anything to the console. But it should not any errors. If it is not setup correctly you will get an error like …

svn: Can't connect to host '<hostname>': No connection could be made because the target machine actively refused it.

For now stop the server by pressing ctrl-c in the console running the server.

If you want to run the server on an ad-hoc basis, you can simply run the above command without the -foreground argument. That will run the server in the background. But the whole point of setting up a server like this is that you don’t need to start/stop it for people access the repositories. We’ll have it start automatically when a request comes in using xinetd.

xinetd should already be installed. If it isn’t, then run:

sudo apt-get install xinetd

Add support for svnserve in xinetd by creating the following file:

/etc/xinetd.d/svnserve

… with the following content:

service svn
{
    port = 3690
    socket_type = stream
    protocol = tcp
    wait = no
    user = svn
    server = /usr/bin/svnserve
    server_args = -i -r /var/repos
}

Now just restart xinetd:

sudo /etc/init.d/xinetd restart

And that’s it. Now you should be able to access your subversion repository on this computer, from other computers in the network.

If you wish to add user authentication, you need to make the following changes to the /var/repos/myrepo/conf/svnserve.conf file:

anon-access = read
auth-access = write
password-db = passwd

… and create a file named passwd in the same directory. This file will contain a list of username/password lines in the following format: username=password.

Author: Musaul Karim

Software Engineer, Hobbyist Photographer, and a bit of a gadget geek.

Leave a Reply

Your email address will not be published. Required fields are marked *