Console Login

Stop Using FTP: Build a Private, High-Speed Git Server with Gitolite on Ubuntu 12.04

Stop Using FTP: Build a Private, High-Speed Git Server with Gitolite on Ubuntu 12.04

I still see it happening. Senior developers, people who should know better, dragging and dropping .php files via FileZilla or, worse, emailing zip archives named project_final_final_v2.zip. If you are managing a development team in 2012 without a proper Version Control System (VCS), you aren't just inefficient; you are negligent.

While Subversion (SVN) has been the enterprise standard for years, the industry is aggressively moving to Git. Distributed version control is not just a fad; it is the new baseline for sanity. But here is the problem: hosting your code on public clouds like GitHub or Bitbucket puts your intellectual property on servers halfway across the world. For Norwegian companies, this introduces two headaches: latency and the Personopplysningsloven (Personal Data Act).

When you type git push, you want it done instantly. You don't want to wait for a handshake with a server in San Francisco. This is why self-hosting on a high-performance VPS in Norway is the superior choice for local teams. Today, we are going to build a fortress-grade Git server using Gitolite on Ubuntu 12.04 LTS.

Why Gitolite?

You might ask, "Why not just use standard SSH accounts?" Because managing Linux user accounts for every junior developer is a security nightmare. You do not want them having shell access to your production environment. Gitolite sits on top of SSH and acts as a gatekeeper. It allows you to manage access control lists (ACLs) for hundreds of repositories and users using a single Unix user. It is lightweight, Perl-based, and rock solid.

Prerequisites

To follow this guide, you need a server that isn't already bogged down by "noisy neighbors." Git operations, specifically garbage collection (git gc) and repacking, are I/O intensive. If you are on a budget host with spinning rust (HDD), your commits will hang. I am performing this deployment on a CoolVDS SSD Instance because the random I/O performance prevents the server from locking up during large merges.

System Specs:

  • OS: Ubuntu 12.04 LTS (Precise Pangolin)
  • RAM: 512MB (Minimum), 1GB (Recommended for larger teams)
  • Disk: SSD Storage (Critical for object database speed)

Step 1: System Preparation

First, log into your VPS as root. We need to ensure our package lists are current. This is standard procedure.

apt-get update
apt-get upgrade -y
apt-get install git-core

Note that on Ubuntu 12.04, the package is git-core. Git version 1.7.9.5 is the current stable release in the repository, which is perfectly adequate for our needs.

Step 2: Create the Git User

We need a dedicated user to handle the repositories. Do not run this as root.

adduser --system --shell /bin/bash --group --disabled-password --home /home/git git

This creates a user named git with no password (SSH key access only) and a home directory.

Step 3: SSH Key Setup

This is where most people get stuck. Gitolite uses the SSH public key of the administrator to initialize itself. You need to generate a key pair on your local workstation (your laptop), not the server.

On your local machine:

ssh-keygen -t rsa -f ~/.ssh/git_admin

Now, upload the public key (git_admin.pub) to your CoolVDS server using scp:

scp ~/.ssh/git_admin.pub root@your-coolvds-ip:/tmp/git_admin.pub

Step 4: Installing Gitolite

Back on your server, switch to the git user and install Gitolite. We will install it into the user's bin directory.

su - git
mkdir -p ~/bin

# Clone the Gitolite source
git clone git://github.com/sitaramc/gitolite

# Install the scripts
gitolite/install -to /home/git/bin

# Setup the admin key
~/bin/gitolite setup -pk /tmp/git_admin.pub

If you see output initializing the empty gitolite-admin repo, you are golden. The system is now locked down. Only the possessor of the private key corresponding to git_admin.pub can configure this server.

Step 5: Configuring Repositories (The Magic Part)

Here is the beauty of Gitolite: you don't configure the server by logging into it anymore. You configure it by pushing code.

Go back to your local workstation. Add an entry to your ~/.ssh/config to make life easier:

Host git-server
    HostName your-coolvds-ip
    User git
    IdentityFile ~/.ssh/git_admin

Now, clone the admin repository:

git clone git-server:gitolite-admin

You will see two folders: conf/ and keydir/.

Adding a New User

To give access to your colleague "Lars":

  1. Get Lars's public SSH key.
  2. Rename it lars.pub.
  3. Drop it into the keydir/ folder.

Adding a New Project

Edit conf/gitolite.conf:

repo gitolite-admin
    RW+     =   admin

repo testing
    RW+     =   @all

repo project-viking
    RW+     =   admin
    RW      =   lars
    R       =   interns

Commit and push these changes:

git add .
git commit -m "Added Lars and Viking project"
git push origin master

When you push, Gitolite's hooks running on the remote CoolVDS server instantly parse the config, create the project-viking.git bare repository, and update the ~/.ssh/authorized_keys file to allow Lars access. It is seamless.

The Latency Advantage

Why go through this trouble instead of using a hosted service? Speed and Data Control.

Action US-Based Cloud CoolVDS (Oslo)
Ping (from Oslo) ~140ms ~2ms
Git Clone (1GB Repo) Slow ramp-up, fluctuating speeds Saturates your fiber line
Data Jurisdiction USA (Patriot Act) Norway (Data Protection Directive)
Pro Tip: If your team is working with large binary assets, Git can get sluggish. Tune your server's memory usage by editing the git config on the server side: git config --global core.packedGitWindowSize 32m. This prevents Git from eating all your RAM on the VPS. However, with CoolVDS's dedicated RAM allocation, this is rarely an issue compared to oversold budget hosts.

Conclusion

You now have a Git server that is faster than GitHub, completely private, and fully under your control. No more FTP. No more email attachments. Just clean, professional version control.

Building this infrastructure requires a foundation that won't crumble under load. While Git is efficient, it demands high disk I/O performance during parallel builds and clones. Don't bottleneck your team's productivity on cheap hardware.

Ready to professionalize your workflow? Deploy a CoolVDS SSD instance today and get your code coming home to Norway.