HowTo: Quick Subversion Server Setup on Linux

This article is heavily based on Setup a Subversion Server in 4 Minutes by Tony Spencer.

To setup subversion (svn) server, all you need is the subversion package installed; on most systems, this already includes all the necessities – the client (svn), the repository tools (svnadmin), and the server (svnserve).

The whole setup is very straight forward; you’ll need root privileges for most of the stuff.

First, lets choose where to keep the repositories (aka the folder you need to backup regularly), and create the repository “repo”:

# create folder to hold repositories
mkdir /svn
# create our repository
svnadmin create /svn/repo

Now, set access rights:

  1. Edit the /svn/repo/conf/svnserve.conf file, adding the lines
    anon-access = none/read/write
    auth-access = write
    password-db = passwd

    Above, you can choose whether anonymous users can do nothing, read (checkout), or write (commit); authenticated users can do anything, and are authenticated based on the data in passwd file.

  2. Edit the /svn/repo/conf/passwd file, adding line(s) like this
    my_user_name = my_awesome_password

    for each user that needs authentication credentials.

This way you can also very easily control access rights for each repository you create in the /svn folder, which gives you better control than just using a single repository for all.

Fire up the server and test it:

svnserve -d
cd ~/projects/repo
svn co svn://my.public.address.com/svn/repo .

If you’ve set anon-access to ‘none’, you’ll be prompted for name/password.

Note: don’t forget to open svn port 3690 in your firewall, and/or forward it in your router, if necessary.

Note on permissions #1: if you’re not overly concerned about security (e.g. the only user on the computer), you can `chmod a+w -R /svn/repo`. There are few problems with permissions that you might run into with the above set up, this will solve them.

Of course, you want the passwd files safe, so you might want to run

for i in `find /svn -name passwd`; do chmod 600 $i; done

Beware that the user, under which you run svnserve has to be able to read the passwd files; if it’s a different user, either transfer the ownership of the files to that user, or set the above permissions to 644.

Note on permissions #2: to be on the safer side, you can create a new user, e.g. svn user. You can then `chown svn:svn -R /svn` and `chmod go-rwx -R /svn` (that is, make all repository folders “property” of the svn user, and remove any access from all other users). All you have to do then is to run the svnserve as the svn user, like this: `sudo -u svn svnserve -d`. This is safer than the above solution, but you have to look out for the permissions more.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s