Setting up a Subversion Server on Ubuntu Gutsy Gibbon server

All the required packages are available in the Ubuntu repositories.

Installing Subversion

Use apt-get:

sudo apt-get update
sudo apt-get install subversion

Creating a Repository

Let's say you want your repository to be in /var/svn/repos, type in these commands:

cd /var
sudo mkdir svn
sudo svnadmin create /var/svn/repos

In order to control who has access to the repository we will now add a user who will own the repository files. Adding a user also adds a group with the same name.

sudo adduser svn

Now make it impossible for anyone to log in as this user by editing /etc/passwd to set the svn user shell to /bin/false. Do this using the vipw command. Find the line which starts svn (it should be the last line in the file) and change /bin/bash to /bin/false.

Now change the ownership of the repository files.

sudo chown -R svn.svn svn

In order for someone to be permitted to use the repository they must be added to the svn group. My user name is martin so I am going to add myself to the svn group.

sudo vigr

Go to the end of the file and add your user name to the end of the line which starts svn. The end of the file should look similar to this:


Now set up an ssh server, clients will connect to this machine using ssh:

sudo apt-get install openssh-server

The repository can now be accessed using the svn+ssh protocol. Test this as follows:

svn co svn+ssh://username@machinename/var/svn/repos

You will be prompted about the RSA fingerprint of the server and asked for your password. You should end up with a directory called repos which is a working copy of your new repository.

As things stand you will be asked for your password every time you connect to the machine which is rather tedious. You can also authenticate with ssh by using a public/private key pair. If you are using a Windows client then install PuTTY and use PuTTYgen to create a key. Don't forget to save the public and private key files. There is a text box at the top of the PuTTYgen window labeled "Public key for pasting into OpenSSH authorized_keys file", you need to put the line of text in that box into a file called .ssh/authorized_keys2 in your home directory on the server. Set the permissions on the files like this:

chmod 0700 .ssh
chmod 0600 .ssh/authorized_keys2

On the Windows machine fire up pageant (another program which comes with PuTTY) and load your private key. You should now be able to connect to the server without being asked for a password. I prefer to disable password based access to the server by editing /etc/ssh/sshd_config and adding the line PasswordAuthentication no.

On a Linux client use ssh-keygen to create the key pair.


Subversion also supports the WebDAV protocol, to set this up Apache is needed. I am assuming that you installed Ubuntu as a LAMP server.

sudo apt-get install libapache2-svn

The following isn't recommended for a real implementation as we are going to add to the default web files. It would be far better to create a new virtual host, but that is a subject itself.

Ubuntu has a file for each active virtual host in /etc/apache2/sites-enabled, after installing Ubuntu server there will be a file called 000-default in the sites-enabled directory and this is the file we are going to edit.

cd /etc/apache2/sites-enabled
sudo vi 000-default

In the directive add:

    <Location /svn/repos>
DAV svn
SVNPath /var/svn/repos

Then execute this command:

sudo /etc/init.d/apache2 force-reload

You should now be able to see the repository at the URL http://machinename/svn/repos.

Securing Web Access

Add this to the location directive:

      AuthType Basic
AuthName "Subversion Repository"
AuthUserFile /etc/apache2/passwords
Require valid-user

Now add a user name and password to the Apache password file:

sudo htpasswd -cb /etc/apache2/passwords martin dgjan08

And another forced reload:

sudo /etc/init.d/apache2 force-reload

Now if you visit the repository URL you will have to enter a valid user name and password.


Trac is a ticketing system and Wiki which integrates very well with Subversion. Start by installing Trac:

sudo apt-get install trac python-setuptools libapache2-mod-python enscript

Now create a Trac database:

sudo mkdir /var/www/trac
sudo trac-admin /var/www/trac/repos initenv

Then answer its questions, take the defaults, our Subversion repository is in /var/svn/repos.

Now to get Apache to run Trac.

cd /var/www
sudo chown -R www-data.svn trac

Head back to /etc/apache2/sites-enabled and edit 000-default again, adding this:

    <Location /trac/[[:alnum]]+/login">
AuthType Basic
AuthName "Subversion Repository"
AuthUserFile /etc/apache2/passwords
Require valid-user

<Location /trac>
SetHandler mod_python
PythonInterpreter main_interpreter
PythonHandler trac.web.modpython_frontend
PythonOption TracEnvParentDir /var/www/trac
PythonOption TracUriRoot /trac

And then run this again:

sudo /etc/init.d/apache2 force-reload

Building Trac from source

If you want the most recent version of Trac (0.10.4) then you will have to build and install it. Do the following:

sudo apt-get remove trac
tar zxf trac-0.10.4.tar.gz
cd trac-0.10.4/
sudo mkdir /usr/local/trac
sudo python install --prefix=/usr

The rest of the instructions are the same.

Site Search

Who's Online

Abbiamo 11 visitatori e nessun utente online



Visite agli articoli
banner mym
banner mym