Philipp's Blog

OpenBSD server: git server


This post is part of a series about OpenBSD. Check out Part 1 and Part 2 as well.


Continuing the OpenBSD series, the following is a quick one about how to set up a basic git server that hosts git repositories for one user.

Firstly, install git, if not already done:

doas pkg_add git

Create a dedicated git user:

doas useradd -m -s /usr/local/bin/git-shell git

If this command fails, make sure to have /usr/local/bin/git-shell added to /etc/shells.


Create the repositories and .ssh directories:

doas mkdir -p /home/git/.ssh /home/git/repos

Paste your SSH key to /home/git/.ssh/authorized_keys.

Fix permissions:

doas chown -R git:git /home/git
doas chmod 700 /home/git/.ssh
doas chmod 600 /home/git/.ssh/authorized_keys

Because we created the git user with the git-shell we can’t login directly. To administer a git repo on the server, use doas -u git. Create a bare repo:

doas -u git git init --bare /home/git/repos/website.git

Clone to your local machine:

git clone git@your-server:repos/website.git

Add to an existing local repo:

git remote add origin git@your-server:repos/website.git
git push -u origin main

Check the commits of a repository:

doas -u git git --git-dir=/home/git/repos/website.git log --oneline

Wrapping up

That’s a really quick one. The next part will be about setting up a mail server with smtpd and dovecot, as well as a few other things. Stay tuned for that!