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.
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
sudoaccess - SSH access to the server (port 22 reachable, or your custom SSH port)
- A client machine with
gitandsshinstalled - A hostname or IP that reaches the server's SSH port directly (see the note below)
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.
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.
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.
Install Gitolite
Debian ships Gitolite as gitolite3, so there is nothing to compile and no extra
dependency to maintain. On the 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:
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.
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.
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.
# 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
Verification
Connect without a command. Gitolite does not give you a shell; it prints a greeting listing the repositories you can access:
ssh gitolite
hello admin, this is gitolite3@your-host running gitolite3 (Debian: 3.6.x) on git 2.x
R W gitolite-admin
R W testing
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.
Manage Repositories and Users
Gitolite is administered by pushing to a special repository. Clone it:
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:
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:
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:
git clone gitolite:myproject
# or push an existing local project
git remote add origin gitolite:myproject
git push -u origin main
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.
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_configwithPasswordAuthentication no, thensudo 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 defaultUMASKof0077keeps repositories private to the gitolite user. - Back up the whole Gitolite home, which contains repositories, keys and configuration:
sudo tar -czf /root/gitolite-$(date +%F).tar.gz -C /var/lib gitolite3
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.