Setting up a SVN Server on a EC2 Instance (Ubuntu 14.04 LTS)

Setting up an SVN server on my EC2 instance (on AWS), is a major problem whenever we connect svn using key-file(key.pem for AWS).
Here’s my situation:
  • I have a micro EC2 instance hosted with Amazon.
  • I used a non-standard port for ssh access
  • I have a pem file provided by Amazon for access through ssh
  • I run Ubuntu 14.04 Server on my EC2 instance
  • On the client side, I’m running Ububtu 14.04 Desktop
With that out of the way, the first thing I had to do was insure svn was installed on my server and Desktop :
sudo apt-get install -y subversion

Then, on my EC2 instance, I want to create both the directory where I’ll store repositories, and the subsequently, create the repository itself. Permissions and ownership are of the utmost importance. This worked for me:
sudo mkdir -p /srv/svn/
sudo chown ubuntu:ubuntu /srv/svn/
svnadmin create /srv/svn/{repo_name}
Mind the {rep_name} placeholder above 

vim /svnrepos/conf/svnserve.conf
In that file add these three lines:
anon-access = none
auth-access = write
password-db = passwd
Create a password file:
vi /svnrepos/conf/passwd
In that file add a line for your user:
# add users in the format : user = password
tony = mypassword


You don’t need to store your svn repos in /srv/svn/. Wherever you’d like, so long as the permissions and ownership is okay. Also, ubuntu:ubuntu is the username and group for my EC2 instance. I believe this is standard now for most AMIs, but change this if appropriate.
I had to do edit some subversion configuration settings. Even command line wasn’t working, because first, we need to create a tunnel
At my ubuntu Desktop (Client) :
vi ~/.subversion/config
Now, under the [tunnels] section, you want to define a rule.
Basically, you want to replicate the syntax that you would normally use for ssh-ing into your EC2 instance. In my case, this includes specifying the pem file path and port I connect through.
So under that [tunnels] section, I have something like this:
ssh-AWS = ssh -q -i /Users/AWS/Keys/awsec2.pem 
A couple things here:
  1. It needs to be the full path to the pem file. You can’t use the ~ here.
  2. It needs to be in the [tunnels] section. I had it at the end of the file at one point, and the tunnel wouldn’t work
Also, you can call you tunnel whatever you want. ssh-AWS or ssh-tunnel or what have you.
And finally, let’s checkout that repo we made
svn co svn+ssh-AWS://ubuntu@1.1.1.1/srv/svn/{repo_name}
In the above case:
  • ssh-AWS is the name you gave to your tunnel
  • ubuntu is the username for your EC2 connection (although I believe ubuntu is the default now)
  • 1.1.1.1 is the IP address (or host if you want) of your EC2 instance
  • {repo_name} is your repository’s name
Yup :)

No comments:

Post a Comment