Run Git Server on Top of Apache with SSL

This article covers the steps to setup a git server on top of apache http server with ssl authentication.

Server side

Make sure you have git and open ssl installed.

Create git dir:

mkdir -p /var/www/html/git

Create git repository:

cd /var/www/html/git
git --bare init [reponame].git
git update-server-info
chown -R apache:apache .

Config apache:

vim /etc/apache2/conf.d/git.conf

Add following:

<Location /git/[reponame].git>
    DAV on
    AuthType Basic
    AuthName "Git"
    AuthUserFile /etc/auth-file
    Require valid-user
    SSLRequireSSL
</Location>

Create auth file:

htpasswd -c /etc/auth-file [myusername]

Restart apache:

sudo service httpd restart

Client side

Clone the repository:

git clone https://[hostname]/git/[reponame].git

For self-signed certificate:
Add “GIT_SSL_NO_VERIFY=true” to your environment variables

Create sample file and push it into empty repository:

cd [reponame]
echo test file > readme.txt
git add readme.txt
git commit
git push origin master

For the following pushes you can simply use:

git push

If you don’t want to be prompted for the password each time and you don’t mind storing it in plain text, edit following file:

vim ~/.netrc

and add following:

machine [hostname]
login [myusername]
password [mypassword]

References:

  1. Git tutorial: http://www.vogella.com/articles/Git/article.html

  2. Use apache auth: http://techblog.zabuchy.net/2012/git-server-with-apache-authentication-on-ubuntudebian/

  3. SSL issue: http://stackoverflow.com/questions/3777075/https-github-access

  4. Git web: http://sourceforge.net/apps/trac/sourceforge/wiki/GitWeb%20repository%20browser

  5. Git cheat sheet: http://help.github.com/git-cheat-sheets/