setting up git daemon
This tutorial explains how to set up a Git daemon on a typical VPS running Linux in two steps:
- systemd configuration
- firewall configuration
This setup will provide two different ways of accessing the service via the Git client:
- access via SSH: read-write access to the repos, reserved for users who have SSH access to the VPS
-
access via the Git protocol: read-only access using a
git://URL, accessible to all users
systemd configuration
You will need to set up a systemd service to run git daemon on the
background. A typical example of such service will look like the following:
# /etc/systemd/system/git-daemon.service
You should replace STORE with the full path of the Git repository store you
want to service. The --export-all flag is used to automatically service all
Git repositories under your store: otherwise git daemon will only service the
repositories containing a file named git-daemon-export-ok inside their root
directories (i.e. the directory containing the actual bare repository).
To avoid any permission issues, the file
/etc/systemd/system/git-daemon.service should be owned by the root user and
should be under the root group. The file should have the following
permissions: -rw-r--r--.
Once you create this file you will need to start the service by running:
# systemctl enable git-daemon.service
# systemctl start git-daemon.service
firewall configuration
The Git protocol runs over TCP at port 9418. When running a firewall, do not
forget to allow this port. For ufw you can use the following command:
# ufw allow 9418/tcp
To confirm the port is allowed, run:
# ufw status verbose | grep 9418
VPS providers typically set up a firewall on their fresh Linux installs, so
you are likely running a firewall even if you never asked for it. The ufw
binary is typically not in your users \$PATH, you need to run it under the
root user or with sudo.