Subversion (svn) on shared web host (bluehost) and Linux client setup

This explains how to configure and use a Subversion client from a GNU/Linux box*  to connect to a Subversion server on a shared web host account.  (bluehost.com)  If you have already set up a shared key for password-less ssh access (see use ssh without a password post), then step 3 can be omitted, but step 3 is useful in case you want to give other people access to a repository on the web host server without giving them full ssh access.

* = I’m guessing any flavor of *nix will work– I use LinuxMint, which is based on Ubuntu

Steps 1 to 3 are performed from the web server (a ssh session to the server)

Step 1 Check to make sure Subversion is installed, or install it.

[~]# svn --version
svn, version 1.7.4 (r1295709)
 compiled Apr 5 2012, 16:46:24

If your web host does not have svn installed, you have to download the tarball, compile,  and install yourself.  (I did this first because I didn’t realize it was already installed.  Bluehost web servers have both svn and git installed as of 2011)  Here are a few guides:

http://www.calzzani.com/blog/?p=61

https://docs.google.com/document/d/1eeiGS6yVjy6h3c04JnRwhOf3KqQG3V-bKP2M_gGGWVQ/edit?hl=en&pli=1

  • source files are no longer at subversion.tigris.org, now at subversion.apache.org
  • the dependencies distribution subversion-deps-* is no longer available,  but there is  a ‘get-deps.sh’ script in the root of the unpacked archive

Step 2 Create a repository

[~]# mkdir repositories/
[~]# cd repositories/
[~/repositories]# svnadmin create testrepo4
[~/repositories]# ls
./ ../ testrepo4/

Step 3 Create a keypair for the repository, for each user

# cd ~/.ssh
[~/.ssh]# ssh-keygen -b 1024 -t dsa -f svntest4
Generating public/private dsa key pair.
Enter passphrase (empty for no passphrase):

I left it blank for no passphrase.  Now you have a two part key, ‘svntest4′ is the name of the private key, ‘svntest4.pub’ is the public key.  The public key needs to be appended to the ‘authorized_keys’ file.  This can be done by clicking authorize key in cPanel, ssh access, manage keys, or just issue this command:

[~/.ssh]# cat svntest4.pub >> authorized_keys

Now edit that file to tie a specific svn user and command to it.  Other options are added to prevent the svn user from using this key to access all ssh functionality.

[~/.ssh]# pico authorized_keys

find the key you just added (should be the last line of the file –note each key takes up only one line) and insert the text shown below in front of the key (begins with ssh-…)(be sure word wrap is turned off)

command="/usr/bin/svnserve -t --tunnel-user=repouser33",no-port-forwarding,no-agent-forwarding,no-X11-forwarding,no-pty

Make the username (‘repouser33′ above) anything you want.  Connecting to Subversion using  svn+shh does not use any of the authorization that is set up in the repository’s ‘conf’ folder (svnserve.conf, passwd, authz) It will use ‘file///’ access and will appear to be connected as the username of your web host account.  The username created in the ‘authorized_keys’ file will show up in the Subversion logs though, and activity will be logged as that username.

Steps 4 and 5 are performed from your local machine

Step 4 Configuring Subversion Client and SSH (Linux)

Copy the private key created in step 3 (I named it ‘svntest4′) to the ‘~/.ssh’ directory on your local machine.  (download by logging into web host cPanel in a web browser, go to SSH access, manage keys, then download private key)  Verify that only the owner has access to the key.   (Permission should be 600)

Edit ‘/etc/ssh/ssh_config’ with a line starting with ‘IdentityFile’ and give the path and name to the key.

 IdentityFile ~/.ssh/svntest4

Step 5 Using the Subversion Client (Linux)

From a command line (terminal window), navigate to a folder where you want the files from the repository to be stored.

/ $ cd ~
~ $ mkdir projectfiles
~ $ cd projectfiles/
~/projectfiles $

issue the Subversion command to checkout the repository

~ $ svn co svn+ssh://username@briangallimore.com/home1/username/repositories/testrepo4

I had a hard time here.  The ‘username’ above is the username of your web host account, not the username of a Subversion user.  The path is the complete path to the repository you want.

Example creating a new local file adding it to the repository (a two-step process using the add and commit functions)

~/projectfiles/testrepo4 $ touch newfilename
~/projectfiles/testrepo4 $ svn add newfilename
A newfilename
~/projectfiles/testrepo4 $ svn commit -m "added a file called newfilename" newfilename
Adding newfilename
Transmitting file data .
Committed revision 2.

The list command will show you what is in the repository without downloading it

~/projectfiles/testrepo4 $ svn list --verbose  svn+ssh://username@briangallimore.com/home1/username/repositories/testrepo4
 2 repouser Dec 22 16:11 ./
 1 repouser 0 Dec 22 15:19 newfile1
 1 repouser 0 Dec 22 15:19 newfile2
 1 repouser 0 Dec 22 15:19 newfile3
 2 repouser 0 Dec 22 16:11 newfilename

The log command will show activity of a file

~/projectfiles/testrepo4 $ svn log newfilename
------------------------------------------------------------------------
r2 | repouser33 | 2013-12-22 16:11:30 -0600 (Sun, 22 Dec 2013) | 1 line
added a file called newfilename
------------------------------------------------------------------------

 

This entry was posted in How-To and tagged , , , , , , , , . Bookmark the permalink.

Leave a Reply