Ubuntu Server: Steps to Create a New SVN Repository and Add Users for it Tips, Tricks and Tutorials 17 DEC 2010

To add SVN repositories and give existing user accounts access to it is not entirely a one step process in Ubuntu. So this is how you do it…

First, browse to the folder in which you want to generate your SVN repository and create the respository folder:

cd /home/svn
mkdir projectname

Next, instruct SVN to generate the necessary file structures required into your repository folder:

sudo svnadmin create projectname

Once this has completed, the next step is to open up the repository to the world by making use of the Apache web server. To do this, we need to assign the necessary folder access permissions:

sudo chown -R www-data:svn projectname
sudo chmod -R g+rws projectname

Next, we need to add the new SVN repository details under Apache’s configuration:

sudo nano /etc/apache2/mods-available/dav_svn.conf

Add to the bottom of the file:

<Location /svn> 
DAV svn 
SVNPath /home/svn/projectname 
AuthType Basic 
AuthName "Projectname SVN Repository" 
AuthUserFile /etc/subversion/passwd 
Require valid-user 
ErrorDocument 404 default 

And finally? Restart the Apache service.

sudo service apache2 restart

Next, you must create /etc/subversion/passwd file. This file contains user authentication details.

If you have just installed SVN, the passwd file will not yet exist and needs to be created using the “-c” switch. Adding any users after that should be done without the “-c” switch to avoid overwriting the passwd file.

To add the first entry, ie.. to add the first user, you can run the following command:

sudo htpasswd -c /etc/subversion/passwd user_name

It prompts you to enter the password. Once you enter the password, the user is added.

To add more users after that, you can run the following command:

sudo htpasswd /etc/subversion/passwd second_user_name

If you are uncertain whether the passwd file exists, running the command below will tell you whether the file already exists:

cat /etc/subversion/passwd

Now, to access the repository you can run the following command:

svn co http://hostname/svn/myproject myproject --username user_name


Related Posts:

About Craig Lotter

South African software architect and developer at Touchwork. Husband to a cupcake baker and father to two little girls. I don't have time for myself any more.