Gitea is the calm, single-binary Git server we reach for when a client wants their code on infrastructure they control — issues, pull requests, Actions, the lot — without GitHub Enterprise pricing or GitLab’s RAM appetite. The install below is what we put down on day one: Postgres on the same box (or external for production), a dedicated git system user, a systemd unit, and Nginx in front handling TLS while SSH passes through on port 22.
How to verify
Pre-check the host. Gitea is light — a 2 GB box is enough for fifty engineers if the database is sized — but the SSH port routing trips up everyone the first time:
free -h
ss -ltnp | grep -E ':(22|80|443|5432)\b'
id git 2>/dev/null || echo "no git user yet"
psql --version 2>/dev/null
which sqlite3
If anything else listens on port 22 (the default SSH daemon), decide now whether Gitea will share that socket or run on a different port. Sharing is doable but adds complexity — we usually move OpenSSH to 2222 and let Gitea own 22.
What’s happening
Gitea is a single Go binary that serves HTTP on one port and SSH on another (or, with START_SSH_SERVER=true, embeds its own SSH listener). The repos live as plain bare .git directories under /var/lib/gitea/git/repositories/<owner>/<repo>.git. Metadata — users, issues, PRs, hooks — lives in the database. The Actions runner is a separate binary that polls the Gitea API and executes job pipelines.
The architectural decision people miss: where SSH lives. Embedded SSH inside Gitea is simple but means git@your-host:owner/repo.git URLs require port 2222 (or rerouting). External SSH (system OpenSSH) keeps port 22 but means you need an authorized_keys shim that calls gitea serv. Both work; we usually use embedded for new deploys and external when SSH is already deeply configured.
The procedure
-
System packages and user.
apt update && apt install -y git postgresql nginx certbot python3-certbot-nginx adduser --system --shell /bin/bash --gecos 'Git Version Control' \ --group --disabled-password --home /home/git git -
Postgres database.
sudo -u postgres psql <<'SQL' CREATE USER gitea WITH PASSWORD 'replace-me' LOGIN; CREATE DATABASE gitea OWNER gitea TEMPLATE template0 ENCODING 'UTF8' LC_COLLATE 'C' LC_CTYPE 'C'; SQL -
Fetch the binary. Always pin a version —
latestworks but you want reproducible installs:GITEA_VERSION=1.22.3 curl -L -o /usr/local/bin/gitea \ https://dl.gitea.com/gitea/${GITEA_VERSION}/gitea-${GITEA_VERSION}-linux-amd64 chmod +x /usr/local/bin/gitea -
Directory layout.
mkdir -p /var/lib/gitea/{custom,data,log} /etc/gitea chown -R git:git /var/lib/gitea chmod -R 750 /var/lib/gitea chown root:git /etc/gitea chmod 770 /etc/gitea -
Systemd unit.
/etc/systemd/system/gitea.service:[Unit] Description=Gitea After=network.target postgresql.service [Service] Type=simple User=git Group=git WorkingDirectory=/var/lib/gitea/ ExecStart=/usr/local/bin/gitea web --config /etc/gitea/app.ini Restart=always Environment=USER=git HOME=/home/git GITEA_WORK_DIR=/var/lib/gitea [Install] WantedBy=multi-user.target -
First boot and web installer.
systemctl daemon-reload systemctl enable --now giteaVisit
http://your-host:3000/, fill in the Postgres credentials, set the SSH port (22 if you moved OpenSSH, 2222 otherwise), setSite URLto your final HTTPS URL, create the admin account. After the installer writes/etc/gitea/app.ini, lock it down:chmod 640 /etc/gitea/app.ini chown root:git /etc/gitea/app.ini -
Nginx reverse proxy with SSH passthrough. For HTTP this is standard. For SSH, use
streamto forward port 22 to Gitea’s embedded SSH on 2222:# /etc/nginx/sites-available/git.example.com server { listen 443 ssl http2; server_name git.example.com; ssl_certificate /etc/letsencrypt/live/git.example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/git.example.com/privkey.pem; client_max_body_size 512M; location / { proxy_pass http://127.0.0.1:3000; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } } -
Enable Actions. In
app.ini:[actions] ENABLED = true DEFAULT_ACTIONS_URL = https://github.comRestart Gitea, then run a runner —
act_runner registerwith the registration token from/admin/actions/runners. -
Initial backup. Use Gitea’s own dump:
sudo -u git gitea dump -c /etc/gitea/app.ini -t /var/tmp -f /var/backups/gitea-$(date +%F).zipThen ship that zip off-host nightly.
Common pitfalls
- The
gituser with a login shell is required for SSH access; annologinshell breaksgit pushover SSH. Site URLset to HTTP after putting TLS in front produces protocol-confused webhook payloads and broken OAuth callbacks — always set it to the public HTTPS URL.- Forgetting
LFSconfiguration means large file pushes silently fall back to regular git storage, which bloats repos; set[server] LFS_START_SERVER = trueand aLFS_JWT_SECRET. - Gitea’s embedded SSH and OpenSSH both bound to port 22 results in only one starting; the other fails silently in logs.
- The Postgres connection without
sslmode=disableto localhost works on Ubuntu’s default config but fails on RHEL-family where Postgres ships with SSL on; explicitly setSSL_MODEin[database].
Stack Harbor runs Gitea as the source-control plane for teams that want their code, issues, and CI/CD pipelines on infrastructure they own — Postgres tuned, Actions runners scaled to the pipeline volume, LFS sized for the asset binaries, and the dump backups shipped off-host every night. The install above is what we deploy on day one, then own through version upgrades, runner version drift, and the schema migrations Gitea ships with every minor release. For teams who want this run as part of a managed environment, our managed operations service is the operating model.