Skip to content

How to Set Up Gitea on a Linux Server – Your Own Git Server for Repositories, Issues, and Actions

Set up Gitea on your Linux server: use a One-Click App with HTTPS and an SSH port, or install it manually with Docker Compose. Includes an admin account, database options, cloning over HTTPS and SSH, backups, and Gitea Actions.

27 November 202612 min read4 Views0 helpful

Introduction

Gitea is a lightweight, self-hosted Git service. You can use it to manage repositories in your browser, work with issues and pull requests, create wikis and releases, and automate tasks such as tests or builds with Gitea Actions. Its interface is similar to GitHub, but your data stays on your own server. This guide shows you two ways to set it up: the easy way, as a One-Click App that makes Gitea available over HTTPS in just a few clicks, and a manual installation with Docker Compose. After that, you’ll create your first repository and clone it over HTTPS or SSH.

When it makes sense to run Gitea on a VPS

Running your own Git server is worthwhile if:

  • You don’t want your code stored with a third-party provider, for example for private projects, client projects, or configuration files.
  • You want to bring together a small team or multiple projects, with users, organizations, and permissions for each repository.
  • You have limited resources: According to the Gitea documentation, 2 CPU cores and 1 GB of RAM are usually enough for small teams and projects.
  • You want to mirror or migrate repositories from GitHub or GitLab to keep your own copy.

Gitea is less suitable if you’re looking for a complete DevOps platform with security scans and large CI/CD pipelines. GitLab is better suited to that, but it requires considerably more memory. See Install GitLab.

Gitea, Forgejo, or GitLab?

The app catalog offers several Git services. Here’s a quick comparison:

GiteaForgejoGitLab
OriginIndependent project, originally a fork of GogsForked from Gitea in October 2022 and developed under the umbrella of the nonprofit Codeberg e.V.Independent platform
InterfaceVery similar to GitHubVery similar to GiteaIts own extensive interface
ResourcesLowLowHigh (GitLab lists 8 GB RAM as a minimum)
CI/CDGitea Actions with its own runnerForgejo Actions with its own runnerGitLab CI/CD with GitLab Runner

Forgejo emphasizes free software and community governance, while Gitea is backed by a company that also offers Cloud and Enterprise versions. Both work well as your own small Git server. This guide covers Gitea.

The easy way: Gitea as a One-Click App

The quickest way to get Gitea running is through your VPS’s One-Click Apps. The app is available directly over HTTPS with a domain; you don’t need a reverse proxy or certificate. The app also opens port 22222 for git clone over SSH.

Which option is right for you?

The app catalog offers Gitea in four options. The only difference is the database:

OptionDatabaseContainers
GiteaSQLite, a single file in the data volume1
Gitea with PostgreSQLPostgreSQL 182
Gitea with MariaDBMariaDB 112
Gitea with MySQLMySQL 8.02

The Gitea option with SQLite is enough for you or a small team. If you expect to have many users and repositories, or prefer a dedicated database, choose Gitea with PostgreSQL. You can’t easily switch options later, so decide before installation. There’s also Gitea Runner, the execution environment for Gitea Actions (see below).

Requirements

  • A Linux VPS (Debian or Ubuntu) with One-Click Apps set up. For instructions, see Set up One-Click Apps.
  • Enough resources: The One-Click App needs only 256 MB of free memory, but 512 MB is recommended. You’ll need more if you use a separate database, have many repositories, or run Actions.

Install

  1. Open your VPS in the ZapX dashboard and go to the One-Click Apps tab.
  2. Search the app catalog for Gitea, select the option you want, and click Install app.
  3. Use a custom subdomain or zap.cloud is already selected, with a randomly generated name. Leave it enabled or enter your own name: You’ll use the domain to access Gitea over HTTPS, and Gitea will use it as the address for clone links.
  4. The Gitea option has no additional fields. For the database options, the app generates a database username and password for you, so you don’t need to enter anything.
  5. Click Queue installation. After one or two minutes, Gitea will show as online on the app card. Under Connection, the card also shows the IP address with SSH port 22222.

Initial setup and admin account

Gitea doesn’t come with default login credentials. The first time you open it, the Initial Configuration page appears. Whoever completes it first creates the administrator account.

Warning

Open Gitea immediately after installation Until you complete the initial setup, anyone who knows the address can open the Initial Configuration page and make themselves an administrator. Open the app’s Access link as soon as the app is online.

  1. Open the app’s Access link.
  2. Leave the database fields at the top unchanged. For the Gitea option, SQLite3 is shown there; for the database options, the app provides the connection details.
  3. Enter 22222 under SSH Server Port. If you leave the default value of 22, the SSH clone links will show the wrong port later.
  4. Gitea Website URL is pre-filled with your domain. Leave it as is.
  5. Select Only administrators can create user accounts (no self-registration) if you don’t want users to register themselves. If you leave it unchecked, any visitor can create an account.
  6. Expand Administrator Account Settings and enter a username, email address, and strong password.
  7. Click Install Gitea. After a few seconds, you’ll be signed in as the administrator.

If you leave Administrator Account Settings blank, the first account registered afterward becomes the administrator. The settings are stored in /data/gitea/conf/app.ini in the data volume.

Correct the SSH address for git clone

During testing, Gitea initially showed the SSH clone address as ssh://git@localhost:22222/... because the One-Click App only sets the domain for HTTPS. You can fix this with an environment variable:

  1. Open the app settings using the gear icon and go to App environment.
  2. Under Custom environment variables, click the plus icon to add a variable: key GITEA__server__SSH_DOMAIN, value your domain without https://, for example, git.example.com.
  3. Click Save. The app will briefly restart and apply the value.

After that, the clone addresses will look like ssh://git@git.example.com:22222/USERNAME/REPO.git. You can set any option from app.ini using the same pattern, GITEA__<section>__<key>. Gitea applies the value each time it starts.

Info

SSH port 22222 Port 22222 is fixed for the app. If you use your own firewall on the server, allow port 22222/tcp. Only one Gitea app can use this port per VPS.

Updates and backups

Update Gitea in the app settings (gear icon), under App update. Click Check for updates and install a new version with Apply update. If the page says the app is up to date, there isn’t a newer version in the app catalog yet.

Repositories, users, and settings are stored in Docker volumes and are retained during updates. However, a volume isn’t a backup. Gitea includes the gitea dump command, which packages everything into a ZIP file. Run this over SSH on your VPS:

Code
C=$(docker ps --format '{{.Names}}' | grep '^gitea-')
docker exec -u git -w /tmp $C bash -c '/usr/local/bin/gitea dump -c /data/gitea/conf/app.ini'
docker exec $C sh -c 'ls /tmp/gitea-dump-*.zip'

Copy the displayed file to the server with docker cp $C:/tmp/FILE_NAME.zip ., then copy it from there to your computer over SFTP. According to the Gitea documentation, the backup is only guaranteed to be consistent if nobody pushes or migrates repositories while it’s running.

Manual installation

The rest of this guide covers a manual installation of Gitea with Docker Compose, following the official Gitea documentation. For example, you might use this approach if you don’t use One-Click Apps on your server or want to manage everything yourself.

Requirements

  • A Linux VPS running Debian or Ubuntu, with SSH access. See First SSH connection.
  • Docker and Docker Compose. See Install Docker. Check the installation with docker --version and docker compose version.
  • For HTTPS: a domain or subdomain with an A record pointing to your VPS’s IP address (for example, git.example.com).
ResourceMinimumRecommended
CPU1 core2 cores
RAM256 MB1 GB
StorageSystem, images, and your repositoriesAdditional space for growth and backups

The minimum matches the One-Click App’s requirements; the recommended value is based on the Gitea documentation for small teams. Allow for more memory if you’re running PostgreSQL and Gitea Actions on the same server.

Prepare the firewall

Gitea uses port 3000 for the web interface and port 22 inside the container for SSH. You’ll access the web interface through the reverse proxy, so you don’t need to open port 3000. For SSH, we’ll use port 2222 on the server because port 22 is already used for the server’s SSH access. With ufw, allow only the ports you need:

Code
ufw allow OpenSSH
ufw allow 80/tcp
ufw allow 443/tcp
ufw allow 2222/tcp
ufw enable
Warning

Docker bypasses ufw Ports published by Docker using ports: are reachable from outside even if ufw blocks them. That’s why you should bind the web interface to 127.0.0.1, as in the Compose file below. For more about the firewall, see Managing the firewall on Linux.

Install with Docker Compose

Create a directory for Gitea and navigate to it:

Code
mkdir -p /opt/gitea
cd /opt/gitea

Create the Compose file with nano docker-compose.yml. It follows the PostgreSQL example in the Gitea documentation:

Code
networks:
  gitea:
    external: false

services:
  server:
    image: docker.gitea.com/gitea:28.4.0
    container_name: gitea
    environment:
      - USER_UID=1000
      - USER_GID=1000
      - GITEA__database__DB_TYPE=postgres
      - GITEA__database__HOST=db:5432
      - GITEA__database__NAME=gitea
      - GITEA__database__USER=gitea
      - GITEA__database__PASSWD=DB_PASSWORD
      - GITEA__server__ROOT_URL=https://git.example.com/
      - GITEA__server__SSH_DOMAIN=git.example.com
      - GITEA__server__SSH_PORT=2222
    restart: always
    networks:
      - gitea
    volumes:
      - ./gitea:/data
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
    ports:
      - "127.0.0.1:3000:3000"
      - "2222:22"
    depends_on:
      - db

  db:
    image: docker.io/library/postgres:18
    restart: always
    environment:
      - POSTGRES_USER=gitea
      - POSTGRES_PASSWORD=DB_PASSWORD
      - POSTGRES_DB=gitea
    networks:
      - gitea
    volumes:
      - ./postgres:/var/lib/postgresql

Here’s what the entries mean:

  • image: Gitea 28.4.0 in a fixed version, as in the One-Click App. This lets you decide when to update.
  • USER_UID and USER_GID: Gitea creates its files in the gitea directory with this user and group ID.
  • GITEA__database__...: The database connection. Replace DB_PASSWORD in both places with the same strong, randomly generated password.
  • GITEA__server__...: The public address, hostname, and port for SSH clone links. Replace git.example.com with your domain.
  • 127.0.0.1:3000:3000: The web interface is only accessible from the server itself. External access goes through the reverse proxy.
  • 2222:22: Server port 2222 forwards to the SSH service in the container.
  • postgres:18: The documentation deliberately pins the major version because PostgreSQL doesn’t automatically migrate data when you change major versions.

If you don’t need a separate database, remove the db service, depends_on, and the GITEA__database__ lines. Gitea will then use SQLite.

Start the containers:

Code
docker compose up -d

Check whether they’re running with docker compose ps and view the logs with docker compose logs -f.

First access

Since the web interface only listens on 127.0.0.1, it’s best to set up the reverse proxy in the next section first, then access Gitea directly at https://git.example.com. Alternatively, open the page from your computer using an SSH tunnel:

Code
ssh -L 3000:localhost:3000 root@SERVER_IP

Replace SERVER_IP with your VPS’s IP address, then open http://localhost:3000 in your browser. The Initial Configuration page will appear. The database is already configured. Check that SSH Server Port is set to 2222 and Gitea Website URL contains your domain. If needed, select the option to disable self-registration, create your admin account under Administrator Account Settings, and click Install Gitea.

Access over HTTPS through a reverse proxy

To access Gitea externally, set up a reverse proxy with a valid certificate in front of it. For the basics, see Set up a reverse proxy with nginx and Create an SSL certificate (Let's Encrypt). Here’s an nginx server block based on the example in the Gitea documentation:

Code
server {
    listen 80;
    server_name git.example.com;

    client_max_body_size 512M;

    location / {
        proxy_pass http://127.0.0.1:3000;
        proxy_http_version 1.1;
        proxy_set_header Connection $http_connection;
        proxy_set_header Upgrade $http_upgrade;
        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;
    }
}

client_max_body_size allows larger uploads; otherwise, nginx stops them with the “413 Request Entity Too Large” error. Gitea needs proxy_http_version and the Upgrade and Connection lines for its WebSocket connection, which is used to update things like the notification counter in real time. Then get a certificate with certbot --nginx -d git.example.com. Certbot adds HTTPS and HTTP redirection to the block. For more security tips, see Linux security tips.

Back up your data

All data is stored in the gitea and postgres directories next to the Compose file. Stop the containers first so the repositories and database stay in sync:

Code
cd /opt/gitea
docker compose stop
tar -czf /root/gitea-backup-$(date +%F).tar.gz gitea postgres docker-compose.yml
docker compose start

Then copy the archive to another storage location.

Update Gitea

Before each update, check the release notes for changes that affect you, and back up your data. Changing the second version number migrates the database to a new format; after that, you can only roll back using a backup. Update the version number in docker-compose.yml and restart Gitea:

Code
cd /opt/gitea
docker compose pull
docker compose up -d

Remove old images with docker image prune. Keep the PostgreSQL image on the same major version.

Create and clone repositories

After setup, create your first repository using the plus icon in the top-right corner > New Repository. Select Initialize Repository to have Gitea create a README file so you can clone it right away. You can migrate existing repositories, for example from GitHub or GitLab, using New Migration in the same menu.

Clone over HTTPS

Find the clone address in the repository by clicking Code and selecting the HTTPS tab:

Code
git clone https://git.example.com/USERNAME/REPO.git

Git will ask for your Gitea username and password. If you’ve enabled two-factor authentication, use an access token instead of your password. You can create one under Settings > Applications.

Clone over SSH

To use SSH, add your public key once under Settings > SSH / GPG Keys > Add Key. For instructions on generating a key pair, see Create an SSH key. Find the address under the SSH tab in Code:

Code
git clone ssh://git@git.example.com:22222/USERNAME/REPO.git

The port is 22222 for the One-Click App and 2222 for a manual installation. During testing, cloning and pushing worked both ways.

Gitea Actions

Gitea Actions has been enabled since version 1.21. During testing, new repositories displayed the Actions tab right away. If it’s missing for you, enable Actions in the repository settings under Settings by selecting Enable Repository Actions. Write workflows in the .gitea/workflows directory, just as you would with GitHub Actions. A Gitea Runner executes them:

  • As a One-Click App: Install the Gitea Runner app. The required fields are GITEA_INSTANCE_URL (the address of your Gitea instance, for example, https://git.example.com) and GITEA_RUNNER_REGISTRATION_TOKEN. You can find the token for an instance-wide runner in the administration area under Site Administration > Actions > Runners (address /-/admin/actions/runners). By default, jobs with the ubuntu-latest label run in a container with Node.js 22.
  • Manual installation: Install the runner as a program or container by following the runner documentation, then register it with the same token.

The Gitea documentation recommends running runners on a different machine from Gitea so builds don’t slow down the Git server. The runner controls Docker on the server, so only use it for repositories you trust. Workflows remain queued if no runner is connected.

Limitations

  • Storage space: Repositories, releases, LFS files, and packages take up space on your VPS. If you run out, increase its size in the Manage plan tab for your VPS.
  • Email: Gitea can’t send notifications or password links without a mail server. Enter the details during initial setup under Email Settings, or later using GITEA__mailer__ variables.
  • Database option: You can’t switch the One-Click App from SQLite to PostgreSQL with a single click.

Conclusion

You’ve set up Gitea on your VPS, created an admin account, and learned how to clone and back up repositories over HTTPS and SSH. You now have your own lightweight Git server for your projects, one that runs well even on small servers.

Prefer not to manage Docker yourself? Take the easy route with the One-Click App, as described above in “The easy way: Gitea as a One-Click App.”

Free tools

Related tools for servers and developers

View all

FAQ

Frequently asked questions

The One-Click App is the quickest option: Gitea is available over HTTPS in a few clicks, SSH cloning uses port 22222, and you can install updates in the ZapX dashboard under App update. Manual installation with Docker Compose is a good choice if you don’t use One-Click Apps or want to configure the ports, database, and reverse proxy yourself.
Gitea doesn’t come with default login details. The first time you open it, the Initial Configuration page lets you create an admin account under Administrator Account Settings. Open Gitea immediately after installation, since anyone with the address could otherwise complete the setup first.
Use port 22222 with the One-Click App, for example: git clone ssh://git@git.example.com:22222/USERNAME/REPO.git. During initial setup, enter 22222 under SSH Server Port and set the GITEA__server__SSH_DOMAIN variable to your domain in the app environment so Gitea displays the correct address. For a manual installation, use port 2222.

Feedback

Was this article helpful?

Your feedback helps us prioritize and improve content.

0 of 0 people found this article helpful.

Personal support

Need more help than the guide provides?

Our ZAP-Hosting support team knows your product — briefly describe your issue and we'll help you personally.

Zappy knows this guide and answers you right in the chat.