SVN/Subversion (SVN) Setup Guide

From Site5Wiki

Jump to: navigation, search

Details on setting up an SVN repository on Site5, locking down permissions and integrating with a desktop client.

This guide was written around setting up an SVN repository on Site5, but there is no reason why this wouldn't work on other hosting services (shared or dedicated).

Contents

[edit] SSH Bash Access

First things first you will need to gain SSH access to your account, once you have access via SSH make sure that default shell is set to bash (usually displayed at the top of your terminal/PuTTY window).

Note: If you are with Site5 you will need to submit a new support ticket to get your SSH shell changed from jailshell to bash.

[edit] Configure Bash

cd ~
# Clean up bash config issue
cp /etc/bashrc .bashrc
nano .bashrc

Press Ctrl+W and search for mesg, if you find it comment out the line "mesg y" -- it should say "# mesg y"
Press Ctrl+X to exit and press Y when prompted to save.

[edit] Creating a new SVN repository

Create a private folder (outside of public_html or www)

cd ~
mkdir svn

Create repository

svnadmin create /home/[site5-username]/svn/[projectx]

Note: The SVN folder will be where we store all of our projects, this differs from the .svn folders (which holds metadata about the files in your project)

[edit] Optional (but recommended) setup the initial SVN structure

mkdir tmpdir
cd tmpdir
mkdir trunk
mkdir branches
mkdir tags

svn import . file:///home/[site5-username]/svn/[projectx] --message 'Initial repository structure'

cd ..
rm -R tmpdir

You can verify the results of the import by running the svn list command:

svn list --verbose file:///home/[site5-username]/svn/[projectx]

[edit] Setup a new SVN user account

Create an authorized keys file for storing the logins in

cd ~
mkdir .ssh
chmod 700 .ssh
touch .ssh/authorized_keys
chmod 600 .ssh/authorized_keys

[edit] Add new user

If you have more than one user to add, you can simply repeat these steps for each user.

ssh-keygen -t rsa

Accept the default file name, the password can be left blank (but if your feeling paranoid a password can be entered). By default it will create two files called id_rsa (the private key that should be downloaded and only be kept on your computer) and id_rsa.pub (the public key which we will use in the next step).

Using nano or an FTP client open up ~/.ssh/authorized_keys and enter the following (all on one line):

command="/usr/bin/svnserve -t -r /home/[site5-username]/svn/[projectx] 
--tunnel-user=[subversion user name]",no-port-forwarding,no-agent-forwarding,no-X11-forwarding,no-pty [public key text from id_rsa.pub]

Make sure that you change [site5-username], [projectx], [subversion user name] and [public key text from id_rsa.pub].

Note: If you get an error message like svn: URL 'svn+ssh://[url]' non-existent in that revision you should remove the -r /home/[site5-username]/svn/[projectx] from the configuration outlined above.

(Before you do that though, note that svnserve's '-r' option changes the root of the filesystem as seen by the client, and therefore the URL that they use to log in should also change. E.g. in the example above, their path will begin after [projectx]. If they're trying to log in using the full path to the repository, they will see the error above.)

The [subversion user name] can be changed to anything you like.

Note: This will allow the user to SSH to your account with their private key, but will give them no access to your server and will only allow SVN activity on that specific repository. Also make sure that you have deleted id_rsa and id_rsa.pub from your server.

[edit] Optional Setup Repository Permissions

By default all users you have setup will be able to read and write to your SVN repository, but if want to give certain users read only access the following can be changed:

Using nano or FTP client open your repository configuration file in /home/[site5-username]/svn/[projectx]/conf/svnserve.conf and uncomment authz-db = authz save and close.

Next open up authz in the same folder and add the following to end of the file:

[/]
* = r
your-svn-username = rw

This will give you read/write access while everyone else will only have read only access. You can keep adding users here and you can even change or add additional repository access levels (e.g. allow some users to write to certain folders, but not others etc).

[edit] Desktop Integration

[edit] Eclipse

Eclipse is a cross-platform integrated/project development environment and supports SVN integration to use your newly created SVN repository open Eclipse and click:

  • File -> Import -> SVN -> Project from SVN (note if this option is not available click Help -> Software Updates -> Manage Configuration and find Subversive and install)
  • Create new repository location
  • URL: svn+ssh://[site5-username]@www.[domain.com]
  • Leave username and password blank
  • Select SSH Settings tab
  • Select Private key and browse for id-rsa and select it, enter the password (if you set one)
  • Press Next (if you get a provide authentication information dialogue press Ok)
  • Select the trunk folder and press Finish
  • Follow the Add new Project wizard to finish checking out your SVN repository

Note: right click the project and press Team -> Synchronize with Repository to commit any changes back to your SVN.

[edit] TortoiseSVN via PuTTY

TortoiseSVN is a Microsoft Windows only shell extension that integrates SVN with Explorer and it can be used in conjunction with PuTTY to connect to your SVN repository. Once installed:

  • Open PuTTYgen load your private key (e.g. id-rsa)
  • Press Save private key, once saved close PuTTYgen
  • Open PuTTY and enter your domain name in the Host Name (e.g. domain.com)
  • Under Connection -> SSH -> Auth select your Private key (you just generated with PuTTYgen)
  • Under Connection -> Data enter your Site5 username in the auto-login username
  • Go back to Session and in Saved Sessions enter a name (e.g. domain) and press Save

Go to your documents:

  • Create a new folder
  • Right click TortoiseSVN -> Settings -> Network -> in SSH client enter: C:\Program Files\TortoiseSVN\bin\TortoisePlink.exe press Ok
  • Right click SVN Checkout...
  • URL: svn+ssh://[PuTTY session name]
  • Press Ok and if you set a password you will prompted for it before it checks out

[edit] See also

[edit] References

  1. Site5 Forums - HowTo Configure Subversion
  2. Julian Yap - SVN on Site5
  3. Queens SVN Howto
  4. TortoiseSVN and PuTTY
  5. Wikipedia Public-key cryptography
Personal tools