Around a year ago, I was introduced to git. I know, I’m pretty late to the party. git is a distributed version control system (DVCS). It quickly took over subversion as my favorite version control system (VCS). I’m a big fan of the social coding site GitHub. For a long time, I’ve wanted to set up a server to host private repositories. GitHub allows private repos, but there’s some data that I can’t host on third-party sites, even if the data is marked private. My home server is running OpenIndiana. This article will show you how to set up a git server inside an OpenIndiana zone.

You will need to set up a new zone. If you don’t have the instructions memorized (like me), you can follow the instructions here. I also delegated a ZFS dataset to the zone to store the repository files. You can learn how to do that by following this.

After creating the zone and delegating the ZFS dataset, you’ll need to create the git user. But first make sure that /export/home exists, otherwise useradd will fail. I set the home directory of the git user to the delegated ZFS dataset. After adding the user, give the user permission to snapshot the dataset: zfs allow git snapshot,mount pool/dataset. We will snapshot the dataset whenever a repository is created or deleted for security reasons. Create the /etc/shells file and place /bin/sh and /usr/gnu/bin/git-shell in it on their own lines. Set the shell of the git user to /usr/gnu/bin/git-shell.

Install sendmail and git. I used the SFE repo for git. If you don’t have the SFE repo set up and don’t know how, this is how you set it up. Enable the smtp/sendmail service. Our script will email us whenever a repo is created or deleted for security auditing purposes.

I created two scripts to help in creating and deleting repositories. Download those scripts and place them in a new directory ~git/git-shell-commands and name the scripts create and delete respectively. Now make the directory ~git/clients. You will need to modify these scripts to change the email address and the dataset that gets snapshotted.

In your /etc/ssh/sshd_config file, you will need to add PermitUserEnvironment yes. Refresh and restart the service. Then, place in the file ~git/.ssh/environment the text PATH=/usr/gnu/bin:/usr/bin:/usr/sbin:/sbin:/bin.

After all this is done, congratulations! You now have a working git server. You will need to add the public ssh key of your clients in ~git/.ssh/authorized_keys. They themselves can ssh in and create/delete repositories. They can use their git client as usual: git clone git@hostname:clients/client_name/repo.git.