SVN/Subversion (SVN) Setup Guide
Creating a New SVN Repository
If you have not already done so, this section will show you how to create a fresh SVN repository and how to setup the initial directory structure (trunk/branches/tags).
First, create a private folder (outside of public_html or www):
cd ~ mkdir svn
Create the 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).
Optional (but recommended) setup the initial SVN structure
cd ~/svn mkdir tmpdir cd tmpdir mkdir trunk mkdir branches mkdir tags svn import . file:///home/[site5-username]/svn/[projectx] --message 'Initial repository structure'
The output will look like this:
Adding trunk Adding branches Adding tags Committed revision 1.
Now go back and remove the “tmpdir” as it is no longer needed:
cd .. rm -rf tmpdir
You can verify the results of the import by running the svn list command:
svn list --verbose file:///home/[site5-username]/svn/[projectx]
The output will look like this (where site5-username is your actual account username):
1 site5-username Dec 30 09:42 ./ 1 site5-username Dec 30 09:42 branches/ 1 site5-username Dec 30 09:42 tags/ 1 site5-username Dec 30 09:42 trunk/
Bash Shell Fix
There is a line (mesg y) inside the global bashrc file that will cause repeated messages when interacting with SVN (stdin: is not a tty). To get rid of this message, you need to make a small modification to your bashrc file. Once logged in via SSH, do the following:
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.
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
First we need to generate RSA key pair (this should be done locally on your workstation):
ssh-keygen -t rsa
Accept the default file name, the password can be left blank (but if you’re 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).
Note: This will create an RSA key for use in SSH protocol 2 connections, the server(s) have had the protocol version 1 disabled so you will want to ensure that your client is using version 2 as well. Otherwise you may receive an error such as “Connection closed unexpectedly.” when trying to initially connect.
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",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] 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 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.)
Note: The command must be entered exactly as given above. If you follow all of the instructions in this document and you are being asked for a password when you try to log in from your subversion client, ensure that there are no spaces between the commas in the command.
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.
If you want to have multiple svn users for this account, then the command in ~/.ssh/authorized_keys should also have the –tunnel-user=<svn username> option given. <svn username> is NOT the site5 username; it is the name you wish the user’s checkins & checkouts to show up under.
Additionally, each svn user will need to provide a separate public key to the administrator; there will be one line per user in authorized_keys using the format already given in the instructions, substituting the public key with the correct public key given by each svn user.
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.
TortoiseSVN via PuTTY
- 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://email@example.com/home/username/path/to/svn/repo
- Press Ok and if you set a password you will prompted for it before it checks out
SVN client on the command line
The official SVN command line client can also be used to connect and perform all the same actions as the above clients (see: SVN Quick Reference Card). On Linux and Mac systems the SVN client normally comes preinstalled, Windows users can install the command line client from: http://www.collab.net/downloads/subversion/. Once installed:
- Open the SVN client config file (on Linux/Mac systems this is normally: ~/.subversion/config)
- Under the [tunnels] section add: site5 = /usr/bin/ssh -p 22 -q -l [site5-username] -i [/full/path/to/your/private/key]
- Save the file and checkout your repository via: svn co svn+ssh://username@[domain.com]/[projectx]