Install and Configure Subversion over SSH on CentOS

Server setup

  1. Install subversion
    root# yum install subversion
  2. Create a Repository. This is where all your files will be stored. You can put this anywhere, such as /var/subversion/repos/mycodes
    root# svnadmin create /var/subversion/repos/mycodes
    root# cd /var/subversion/repos/mycodes/conf
    root# vi svnserve.conf

    Now add the following into the file svnserve.conf:
    anon-access = none
    auth-access = write
  3. Setup a svn group. You'll need all your users to be members of the same group. I generally setup an svn group, and give access to anybody who needs to access subversion.  
    root# groupadd svn
  4. # Give your group ownership of the repos directory.
    root# chown -R :svn /var/subversion/repos/
  5. Set permissions on same.
    root# chmod -R 775 /var/subversion/repos/  
  6. Setup a user for each person who needs svn access, and add them to the svn group.
    root# usermod -a -G svn userid1
  7. Create a wrapper for svnserve. svnserve is the server component of subversion; when your subversion client connects via SSH, it spawns an instance of svnserve running under your user account. The problem here is the 'under your user account' part; that means it is running under your user account's permissions setup. By default, your permissions don't allow anyone else access to your files, and yet svnserve is going to be writing files in the common user directory at /var/subversion/repos that everyone needs write access to. Therefore, we can create a wrapper script that sets a umask for group-writable peermissions right before svnserve is called: 
    #!/bin/sh
    # set the umask so files are group-wriable
    umask 002
    # call the 'real' svnserve, also passing in the default repo location
    exec /usr/bin/svnserve-daemon "$@" -r /var/svn/repos

    Save this somewhere, like /usr/local/bin/svnwrapper.sh. Move the real svnserve, and put the wrapper in its place:
    root# cd /usr/bin
    root# chmod 755 /usr/local/bin/svnwrapper.sh
    root# mv svnserve svnserve-daemon
    root# ln -s /usr/local/bin/svnwrapper.sh svnserve
  8. Import your initial directory set. Generally, you'll want a set of directories called 'trunk', 'tags' and 'branches' at the lowest level of your repository. To get this setup:
    user1$ mkdir code
    user1$ mkdir code/trunk
    user1$ mkdir code/tags
    user1$ mkdir code/branches
    user1$ svn import code svn+ssh://USERNAME@SERVER/my_code -m 'inital import'
    user1$ rm -rf code

Client setup

To checkout files, go to your local machine and issue a checkout command:

user$ svn co svn+ssh://USERNAME@SERVER/my_code my_code_local_dir

Note: To setup Subversion over Apache, check: http://wiki.centos.org/HowTos/Subversion

Comments

Unable to commit changes

I've followed this and had no problems getting it working. But when I try to check in my changes I run into problems. See the error below. Do I need to make pub/private keys? Do I need a similar wrapper for svn?

Transmitting file data ……..svn: Commit failed (details follow):
svn: Can't open file '/var/subversion/repo/db/txn-current-lock': Permission denied

I've seen this error myself

I've seen this error myself too. When I checked, it appeared that I forgot the chown or chmod on /var/subversion/repos/. Check the user, group, and permission on that directory and everyting below. Then do:

chown -R :svn /var/subversion/repos/
chmod -R 775 /var/subversion/repos/

This should work. At least it fixed the problem for me.