Back to blog
February 2, 2026Guides

How to Set Up a Private Git Server on VPS

Complete guide to setting up your own private Git server on a VPS. Learn how to host Git repositories with full control and privacy using GitLab, Gitea, or bare repositories.

How to Set Up a Private Git Server on VPS

Hosting your own Git server gives you complete control over your code repositories, ensuring privacy and avoiding reliance on third-party services. Whether you need a simple bare repository or a full-featured Git hosting platform, this guide covers multiple options for setting up a private Git server on your VPS.

Why Host Your Own Git Server?

  • Complete privacy: Your code stays on your server
  • No vendor lock-in: Full control over your repositories
  • Customization: Configure exactly how you want
  • Cost-effective: One server for unlimited repositories
  • Compliance: Meet data residency requirements
  • Learning: Understand Git server internals

Option 1: GitLab (Full-Featured)

GitLab provides a complete DevOps platform:

bash
curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | bash
apt install gitlab-ce

gitlab-ctl reconfigure
# Access GitLab at http://your-server-ip
# Default username: root
# Set password on first login

Option 2: Gitea (Lightweight)

Gitea is a lightweight, self-hosted Git service:

bash
wget -O gitea https://dl.gitea.io/gitea/1.21.0/gitea-1.21.0-linux-amd64
chmod +x gitea
mv gitea /usr/local/bin/

# Create systemd service
nano /etc/systemd/system/gitea.service
# Configure and start Gitea
systemctl enable gitea
systemctl start gitea

Option 3: Bare Git Repository (Simple)

For basic Git hosting without a web interface:

bash
mkdir -p /srv/git/myproject.git
cd /srv/git/myproject.git
git --bare init

# Set proper permissions
chown -R git:git /srv/git
chmod -R 755 /srv/git

# Clone from client:
git clone git@your-server:/srv/git/myproject.git

SSH Access Configuration

Set up SSH for secure Git access:

bash
adduser git
su - git
mkdir .ssh
chmod 700 .ssh
nano .ssh/authorized_keys
# Add public keys of developers
chmod 600 .ssh/authorized_keys

# Test connection:
ssh git@your-server

Security Best Practices

  • Use SSH keys instead of passwords
  • Enable two-factor authentication (GitLab/Gitea)
  • Regular backups of repositories
  • Keep Git server software updated
  • Configure firewall to restrict access
  • Use SSL/TLS for web interfaces
  • Implement access controls and permissions
  • Monitor logs for suspicious activity

Backup Strategy

Regular backups are essential:

bash
#!/bin/bash
# Git repository backup script
BACKUP_DIR="/backup/git"
REPO_DIR="/srv/git"
DATE=$(date +%Y%m%d)

tar -czf $BACKUP_DIR/git-backup-$DATE.tar.gz $REPO_DIR
# Keep last 30 days
find $BACKUP_DIR -name "*.tar.gz" -mtime +30 -delete