Hosting your own Git server gives you full control over your code, unlimited private repositories, and no per-user pricing from services like GitHub or GitLab. Gitea is a lightweight, self-hosted Git service written in Go that runs comfortably on a 1 GB VPS and provides a GitHub-like experience with minimal overhead. This step-by-step guide walks through installing Gitea on a VPS, configuring a reverse proxy with Nginx, setting up HTTPS with Let’s Encrypt, and adding SSH access for your team.
Prerequisites
- A Linux VPS with at least 1 GB RAM and 10 GB storage (Ubuntu 24.04 LTS recommended)
- A domain name pointing to your VPS (e.g., git.yourdomain.com)
- Root or sudo access
- Git installed on the server (
sudo apt install git)
Before you begin, compare VPS specs for development to ensure your provider offers the storage and bandwidth you need for code hosting.
Step 1: Install Gitea
Gitea distributes as a single binary with no external dependencies beyond a database. The recommended deployment uses SQLite for small teams (under 10 users) or PostgreSQL for larger deployments. We will use SQLite for simplicity.
First, create the gitea system user and required directories:
sudo adduser --system --group --disabled-password --shell /bin/bash --home /home/gitea gitea
sudo mkdir -p /var/lib/gitea/{custom,data,log}
sudo chown -R gitea:gitea /var/lib/gitea
sudo chmod -R 750 /var/lib/gitea
Download the latest Gitea binary from the official releases page:
cd /tmp
wget -O gitea https://dl.gitea.com/gitea/1.22/gitea-1.22-linux-amd64
sudo mv gitea /usr/local/bin/gitea
sudo chmod +x /usr/local/bin/gitea
Step 2: Configure Gitea as a Systemd Service
Create a systemd unit file so Gitea starts automatically on boot and can be managed with standard systemctl commands:
sudo nano /etc/systemd/system/gitea.service
[Unit]
Description=Gitea (Git with a cup of tea)
After=network.target
[Service]
Type=simple
User=gitea
Group=gitea
WorkingDirectory=/var/lib/gitea
ExecStart=/usr/local/bin/gitea web --config /etc/gitea/app.ini
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
Create the Gitea configuration directory and start the service:
sudo mkdir -p /etc/gitea
sudo chown root:gitea /etc/gitea
sudo chmod 770 /etc/gitea
sudo systemctl daemon-reload
sudo systemctl enable --now gitea
Step 3: Initial Configuration via Web UI
Gitea starts on port 3000 by default. For initial setup, temporarily open port 3000 in your firewall or use an SSH tunnel:
sudo ufw allow 3000/tcp
Visit http://YOUR_VPS_IP:3000 in your browser. The installation page asks for:
- Database type: SQLite3 (recommended for small teams)
- Site title: Your organization name
- Repository root path: /home/gitea/git/repositories
- SSH server domain: Your domain (e.g., git.yourdomain.com)
- Gitea HTTP listen port: 3000
- Server domain: git.yourdomain.com
After submitting the form, Gitea creates the configuration file at /etc/gitea/app.ini. Secure the config directory:
sudo chmod 750 /etc/gitea
sudo chmod 640 /etc/gitea/app.ini
Step 4: Set Up Nginx Reverse Proxy with HTTPS
Now configure Nginx as a reverse proxy so Gitea is accessible at https://git.yourdomain.com. First, obtain an SSL certificate with Certbot:
sudo apt install -y nginx certbot python3-certbot-nginx
sudo certbot --nginx -d git.yourdomain.com
Then create the Nginx site configuration:
sudo nano /etc/nginx/sites-available/gitea
server {
listen 80;
server_name git.yourdomain.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
server_name git.yourdomain.com;
ssl_certificate /etc/letsencrypt/live/git.yourdomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/git.yourdomain.com/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
client_max_body_size 512M;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
Enable the site and reload Nginx:
sudo ln -s /etc/nginx/sites-available/gitea /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
Update Gitea to use the proper domain by editing /etc/gitea/app.ini:
[server]
DOMAIN = git.yourdomain.com
ROOT_URL = https://git.yourdomain.com/
HTTP_PORT = 3000
PROTOCOL = http
[service]
DISABLE_REGISTRATION = true
Set DISABLE_REGISTRATION = true to prevent public signups — you will create accounts for your team manually. Restart Gitea: sudo systemctl restart gitea. Close the temporary firewall rule: sudo ufw delete allow 3000/tcp.
Step 5: Configure SSH Access for Git Operations
Gitea supports two SSH modes: built-in SSH server (port 222) or using the system SSH daemon. For simplicity, we will configure Gitea to use the system SSH on port 22. Edit /etc/gitea/app.ini:
[server]
SSH_DOMAIN = git.yourdomain.com
SSH_PORT = 22
SSH_LISTEN_PORT = 22
SSH_USER = gitea
START_SSH_SERVER = false
Now add the gitea user’s key to the system SSH authorized keys. Gitea manages keys through its web UI — when a user adds an SSH key in Gitea, it writes to /home/gitea/.ssh/authorized_keys. Ensure the authorized_keys command wrapper is configured by adding this line to /etc/gitea/app.ini if not already present:
[ssh]
MINIMUM_KEY_SIZE_CHECK = false
Users can now clone repositories using SSH:
git clone [email protected]:username/repository.git
Step 6: Adding Users and Creating Repositories
Log into Gitea as the admin user (the first registered user becomes admin). From the admin panel, you can:
- Create user accounts for team members
- Create organizations and teams with granular permissions
- Enable repository mirroring to sync with external Git hosts
- Configure webhooks for CI/CD integration
- Enable Gitea Actions for built-in CI/CD pipelines
Step 7: Backup and Maintenance
Gitea includes a built-in dump command for backups. Set up a daily cron job:
sudo crontab -e
0 3 * * * /usr/local/bin/gitea dump -c /etc/gitea/app.ini -f /var/backups/gitea/$(date +\%Y\%m\%d)-gitea.zip
Keep at least 7 days of backups and offload them to a secondary location (S3, rsync to another server, etc.).
Conclusion
You now have a fully self-hosted Git server running Gitea on your VPS, complete with HTTPS, SSH access, and team collaboration features. Gitea’s lightweight footprint means it shares resources comfortably with other services on the same VPS. For VPS providers with the storage and bandwidth to match your development needs, compare VPS specs for development on our comparison table.




Leave a Reply
You must be logged in to post a comment.