Are you looking for a lightweight alternative to GitHub or GitLab for personal projects, internal testing, or simply to have full control without relying on third parties?
Setting up a pure Git server over SSH remains, in 2026, one of the simplest, most secure, and most efficient solutions available. You get complete control, zero unnecessarily exposed web services, and remarkably low resource consumption.
In this guide, we will set up a minimalist Git server using only native operating system tools. No Docker, no databases, no web interfaces. The result: a server that typically consumes between 5 and 50 MB of RAM and, once configured, requires virtually zero maintenance.
Why Pure SSH Instead of Gitea, Forgejo, GitLab…?
This approach is not meant to compete with full-featured platforms. It simply excels when your top priorities are:
- Exceptional efficiency: 5–50 MB of RAM vs. the hundreds of MB or GB demanded by solutions with a web interface.
- Minimalist security: You only expose the SSH port (ideally changed from the default port 22). No need to constantly patch vulnerabilities in Nginx, Unicorn, Redis, etc.
- Almost zero maintenance: Git is exceptionally stable. Once set up, you only need to worry about backups.
Clear limitations (so there are no surprises):
You will not get pull requests, issues, wikis, or a slick UI. However, if the project grows and you end up needing those features, you can always install cgit or Gitea, or migrate to Forgejo later without losing a single commit.
Prerequisites
- A VPS running Linux (works seamlessly on Debian 12/13 and Ubuntu 22.04/24.04 LTS).
- Sudo privileges.
- Git installed on both your local machine and the server.
- An SSH key (I recommend ed25519 for security and performance).
Install Git on the server (if it is not already installed):
sudo apt update && sudo apt install git -y
Step 1: Create a Dedicated User (Security First)
Never use root or your primary user account to host repositories. We create a git user with a restricted shell that only permits executing Git commands.
sudo adduser \
--system \
--shell /usr/bin/git-shell \
--group \
--home /home/git \
--disabled-password \
git
Step 2: Directory Structure and Permissions
Right from the start, organize repositories by category to avoid chaos once you have 20 or 30 projects.
sudo mkdir -p /home/git/repositories/personal
sudo mkdir -p /home/git/repositories/equipo
sudo chown -R git:git /home/git
sudo chmod 700 /home/git
Step 3: Configure SSH Key Access (No Passwords)
sudo mkdir -p /home/git/.ssh
sudo touch /home/git/.ssh/authorized_keys
sudo chmod 700 /home/git/.ssh
sudo chmod 600 /home/git/.ssh/authorized_keys
sudo chown -R git:git /home/git/.ssh
Important Security Tip:
When adding keys to the authorized_keys file, use the restriction prefix so that the key can only be used for Git and nothing else:
no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-ed25519 AAAAC3...tu_clave_pública... aqui@tu-laptop
Step 4: Create a Bare Repository on the Server
Because the git user has a restricted shell, we create repositories from a user with sudo access:
sudo -u git git init --bare /home/git/repositories/personal/mi-proyecto.git
Step 5: Connect Your Local Project to the Server
If you already have a local project, simply add the remote.
Important: If you changed the SSH port (highly recommended for security), use the full syntax specifying the port.
# Entra en tu carpeta de proyecto local
cd mi-proyecto
# Si es un proyecto nuevo
git init
git add .
git commit -m "Primer commit"
# Añadir el remote (ejemplo con puerto 2222)
git remote add origin ssh://git@TU_IP_O_DOMINIO:2222/home/git/repositories/personal/mi-proyecto.git
# Renombrar rama principal (si es necesario) y subir
git branch -M main
git push -u origin main
Step 6: Quick Repository Creation Script (Basic Automation)
To avoid typing the same command every time, you can keep this small script on your local machine (save it as git-create.sh and grant it execution permissions):
#!/usr/bin/env bash
REPO_NAME="$1"
# Cambia estos valores según tu setup
SERVER="tu-vps.com"
PORT="2222"
ADMIN_USER="tu_usuario_con_sudo"
if [ -z "$REPO_NAME" ]; then
echo "Uso: ./git-create.sh nombre-del-repo"
exit 1
fi
ssh -p "$PORT" "$ADMIN_USER@$SERVER" "sudo -u git git init --bare /home/git/repositories/personal/$REPO_NAME.git"
echo "¡Repositorio creado!"
echo "Conéctalo con:"
echo "git remote add origin ssh://git@$SERVER:$PORT/home/git/repositories/personal/$REPO_NAME.git"
Step 7: Simple (and Effective) Backups
Because bare repositories are simply directories, backing them up with rsync is trivial:
rsync -avz -e 'ssh -p 2222' git@TU_IP:/home/git/repositories/ /ruta/local/de/backup/
Or to another remote server:
rsync -avz -e 'ssh -p 2222' /home/git/repositories/ backup@otro-servidor:/backups/git/
That’s It: Your Own Git Server on a VPS Using Only SSH
Setting up your own Git server over SSH not only grants you privacy and full control over your projects, but it also helps you gain a much deeper understanding of how Git works under the hood. It is an elegant, lightweight, and professional solution that fits perfectly into any modern workflow, from side projects to internal or testing environments.
In an upcoming article, I will explain how to use Git Hooks for automated deployment: having every git push automatically update your website or production application without manual intervention.
What do you think of this setup? Have you tried it on Debian 13, or do you have any extra tricks for managing multiple users and keys? If you have questions (about non-standard ports, SSH hardening, etc.), feel free to leave a comment.