Private Git Server on Linux

There are several ways to self-host a Git server. This guide covers the simplest option — a bare repository accessed over SSH — which works well for small trusted teams. For a full web interface with pull requests and issue tracking, see the modern alternatives section at the end.

SSH-based bare repository

All contributors need SSH access to the server and Git installed on both sides (apt install git / dnf install git).

Prepare the server

Create a group for contributors:

groupadd git-users

Create a user for each contributor and assign them to the group:

useradd -m -g users -G git-users -s /bin/bash contributor1
passwd contributor1

Repeat for each contributor.

Create the repository

mkdir -p /srv/git-repos
git init --bare /srv/git-repos/project.git
chown -R root:git-users /srv/git-repos/
chmod -R g+rwX /srv/git-repos/

g+rwX gives the group read/write access and sets the setgid bit on directories so new files inherit the group automatically.

Clone and push

From a contributor's workstation, clone the repository:

git clone contributor1@your-server:/srv/git-repos/project.git

Or add it as a remote to an existing local repository:

git remote add origin contributor1@your-server:/srv/git-repos/project.git
git push -u origin main

SSH key authentication (recommended)

Password-based login works but SSH keys are more secure and allow automation. On each contributor's machine:

ssh-keygen -t ed25519 -C "contributor1"
ssh-copy-id contributor1@your-server

Modern alternatives — Gitea and Forgejo

If you need a web UI with pull requests, issue tracking, user management, and repository browsing, the two leading self-hosted options are:

Both expose the same SSH-based Git workflow underneath, so you can start with the bare-repo approach above and migrate to Gitea/Forgejo later without losing history.


Last updated on: June 26, 2026

By: Guillermo Garron