How to Set Up a Secure Self-Hosted Git Server Using Gitea

For developers and teams who want full control over their code repositories, a self-hosted Git server is a great alternative to services like GitHub and GitLab. Gitea is a lightweight, open-source Git hosting solution that offers a fast and simple way to manage repositories. In this guide, we’ll walk you through setting up a secure self-hosted Git server using Gitea.

1. Prerequisites

  • A server (VPS or on-premises) with at least 1 CPU core and 512MB RAM.
  • A domain or static IP address.
  • Basic knowledge of Linux command-line operations.
  • Docker installed on the server (recommended for easy setup).

2. Install Gitea with Docker

Using Docker simplifies deployment and keeps Gitea isolated from other services on your server. Run the following commands to set up Gitea:

mkdir -p /opt/gitea/{data,config}
docker run -d --name gitea \
  -p 3000:3000 -p 2222:22 \
  -v /opt/gitea/data:/data \
  -v /opt/gitea/config:/config \
  --restart=always \
  gitea/gitea:latest

This will download and start the Gitea container, exposing the web interface on port 3000 and SSH access on port 2222.

3. Configure Gitea

Once the container is running, open your browser and navigate to http://your-server-ip:3000. Follow the setup wizard:

  • Choose SQLite, PostgreSQL, or MySQL as your database (PostgreSQL recommended).
  • Set the repository root path.
  • Configure SSH and HTTP settings.
  • Create an administrator account.

4. Secure Your Git Server

To enhance security, consider these measures:

  • Enable HTTPS using a reverse proxy like Nginx with Let’s Encrypt SSL certificates.
  • Restrict SSH access to only trusted users by modifying the SSH daemon settings.
  • Regularly update Gitea to patch security vulnerabilities.

5. Using Gitea

Now that Gitea is up and running, you can create repositories, manage users, and integrate CI/CD tools for automated workflows. Clone a repository using:

git clone ssh://git@your-server-ip:2222/username/repository.git

Conclusion

A self-hosted Git server with Gitea provides flexibility and security while allowing complete control over your code. With proper configuration and security measures, you can ensure a robust development workflow without relying on third-party services.

Illustration of Gitea Git Server Setup:

Comments

Popular Posts

Install Ollama and Open WebUI on Ubuntu 24.04 with NVIDIA GPU Acceleration (Step-by-Step)

Install Ollama + Open WebUI on Ubuntu 24.04 with NVIDIA GPU Acceleration (Step-by-Step)

Install a Local AI Chatbot on Ubuntu 24.04 with Ollama and Open WebUI (Step-by-Step)

Trending Now

Recovering from Btrfs Boot Failures Using GUI Tools on Fedora

By the end of this guide the reader will be able to identify a Btrfs‑based Fedora installation, boot from a live USB, list and restore snapshots using the graphical utilities btrfs‑assistant and snapper, and verify that the system returns to a functional state without resorting to the command line. Understanding the Btrfs Layout Used by Fedora Fedora Workstation and Fedora KDE install the root filesystem as a single Btrfs partition that contains two default sub‑volumes. One sub‑volume holds the traditional “/” hierarchy, while the second is dedicated to /var/lib/machines . The latter exists to keep container images out of snapshot operations; it remains empty on systems that do not run virtual machines. Because Btrfs stores data in sub‑volumes rather than separate partitions, a snapshot captures the state of an entire sub‑volume at a point in time. The installer (Anaconda) automatically registers these sub‑volumes with the snapper service. Snapper maintains a series of read‑only ...