geek.sonde.uk updated:
Git Self-hosted Debian 13

Self-Host Git with Gitolite

Install Gitolite on a Debian 13 VPS and manage users, keys and per-repository permissions from a single config file kept in a Git repository — no web UI, no database, no daemon.

~10 min read Debian 13 (Trixie) · macOS / Linux client Difficulty: Intermediate
01

Prerequisites

Gitolite is a thin layer on top of plain SSH and Git. It runs as a dedicated system user and uses authorized_keys with forced commands to decide who can read or write what. Before you begin, make sure you have:

  • A Debian 13 (Trixie) server with root or sudo access
  • SSH access to the server (port 22 reachable, or your custom SSH port)
  • A client machine with git and ssh installed
  • A hostname or IP that reaches the server's SSH port directly (see the note below)
⚠️
Cloudflare-proxied domains

If your domain is behind the Cloudflare proxy (orange cloud), SSH will not work through it — only HTTP(S) is proxied. Use a DNS-only (grey cloud) record such as git.example.com, or the server's IP address, as the Git/SSH hostname. Your origin firewall rules for ports 80/443 do not affect SSH, but make sure the SSH port is open.

02

Create the Admin Key

Gitolite identifies users by their SSH public key, and the file name of the key becomes the username. Create a dedicated key for the administrator on your client machine, and name the public key admin.pub when copying it to the server so the admin user is called admin.

bash client
ssh-keygen -t ed25519 -f ~/.ssh/gitolite_admin -C "gitolite admin"
scp ~/.ssh/gitolite_admin.pub youruser@your-server:/tmp/admin.pub

The file only needs to be world-readable for a moment: the installer reads it, and you will delete it in the next step.

03

Install Gitolite

Debian ships Gitolite as gitolite3, so there is nothing to compile and no extra dependency to maintain. On the server:

bash server
sudo apt update && sudo apt install -y gitolite3

The package asks three questions through debconf. The defaults are fine:

  • Gitolite user: gitolite3
  • Repository path: /var/lib/gitolite3
  • Administrator's SSH public key: /tmp/admin.pub

Once it finishes, remove the temporary key and check the result:

bash server
rm /tmp/admin.pub
sudo ls -la /var/lib/gitolite3

You should see .ssh, .gitolite and repositories. The repositories directory already contains gitolite-admin.git and testing.git.

ℹ️
Wrong key or typo?

Re-run the setup questions with sudo dpkg-reconfigure gitolite3. If your sshd_config uses AllowUsers or AllowGroups, add the gitolite3 user there too, then reload sshd.

04

Configure the SSH Client

Add a host alias on your client so that Git always uses the right key and user. This keeps clone URLs short (gitolite:repo) and prevents SSH from offering every key in your agent.

config ~/.ssh/config
# Use a DNS-only hostname or the server IP, not a Cloudflare-proxied name
Host gitolite
    HostName git.example.com
    User gitolite3
    # Port 2222   # uncomment if sshd listens on a non-standard port
    IdentityFile ~/.ssh/gitolite_admin
    IdentitiesOnly yes
05

Verification

Connect without a command. Gitolite does not give you a shell; it prints a greeting listing the repositories you can access:

bash client
ssh gitolite
output
hello admin, this is gitolite3@your-host running gitolite3 (Debian: 3.6.x) on git 2.x

 R W    gitolite-admin
 R W    testing
✅
Success

If you see hello admin and the two repositories above, Gitolite is installed and recognises your key. If SSH asks for a password instead, the key was not picked up: re-check IdentityFile and the file name used in step 02.

06

Manage Repositories and Users

Gitolite is administered by pushing to a special repository. Clone it:

bash client
git clone gitolite:gitolite-admin
cd gitolite-admin
ls conf keydir

keydir/ holds one .pub file per user and conf/gitolite.conf defines repositories and permissions. Edit the config to create a repository and grant access:

config conf/gitolite.conf
repo gitolite-admin
    RW+     =   admin

repo myproject
    RW+     =   admin
    R       =   alice

To add a user, drop their public key into keydir/ named after the username (alice.pub), then commit and push. Gitolite rewrites authorized_keys on the server by itself:

bash client
cp /path/to/alice.pub keydir/alice.pub
git add -A
git commit -m "Add repo myproject and user alice"
git push

The new repository is created on the server as soon as the push completes. Use it like any other remote:

bash client
git clone gitolite:myproject

# or push an existing local project
git remote add origin gitolite:myproject
git push -u origin main
ℹ️
Permission cheat sheet

R read only · RW read/write · RW+ read/write plus force-push and branch deletion. Group users with @team = alice bob and reuse @team in rules. Remove the testing repo from the config if you do not need it.

07

Hardening and Backup

Gitolite already restricts every key to a forced command, so users never get a shell. A few extra steps are still worth taking:

  • Disable password logins in /etc/ssh/sshd_config with PasswordAuthentication no, then sudo systemctl reload ssh.
  • Keep the admin key passphrase-protected and never share it; hand out separate keys per user and per device.
  • Review ~gitolite3/.gitolite.rc: the Debian default UMASK of 0077 keeps repositories private to the gitolite user.
  • Back up the whole Gitolite home, which contains repositories, keys and configuration:
bash server
sudo tar -czf /root/gitolite-$(date +%F).tar.gz -C /var/lib gitolite3
🛑
Do not lose the admin key

If the only admin key is lost, you can no longer push to gitolite-admin. Recover with sudo dpkg-reconfigure gitolite3 and a new key, or keep a second admin key (admin2.pub) listed in gitolite.conf from the start.