August 15, 2025

Set up a cgit instance on a Nginx web server

Note: I took these notes a few months, when I started to set up my own cgit instance. There might be some omissions, or mistakes. Feel free to email me if you have questions.

Create a user git

I read that it’s best to create a dedicated user, so that if many contributors need to access the remote repository on the VPS, the maintainer/admin only needs to provide others with the SSH access to the user git (or whatever you want to call it), not the whole directory with the repositories.

To create a user run:

adduser git

Choose password for the user git; you should not need this password since your local machine will authenticate to the server via SSH; plus password authentication should be disabled.

Switch from root to user git:

# su git

Set up SSH

Make sure you are in the home i.e. ~ directory:

/$ cd
~$ 

Notice the ~.

Create a .ssh directory:

~$ mkdir .ssh

Make sure .ssh is only accessible by user git:

~$ chmod 700 .ssh

Create a file that will hold the SSH public keys of users who are authortized to access the remote repository we are creating:

~$ touch .ssh/authorized_keys

Make this file only accessible by user git:

~$ chmod 600 .ssh/authorized_keys

So far we’ve been on the VPS only; now we go onto the local machine.

Copy your own SSH public key to the server

We will copy the SSH public key of the (local) user onto the VPS, so the user can interact with the remote repository:

$ ssh root@vps_ip_address 'cat > /home/git/.ssh/authorized_keys' < .ssh/id_key

What does this command do?

  • we SSH into the VPS via root
  • we feed the file /home/git/.ssh/authorized_keys with the key of the file .ssh/id_key.

You can check that the SSH public key of local user was copied to /home/git/.ssh/authorized_keys:

~$ cat .ssh/authorized_keys 
ssh-rsa BBBBeB....k8d53kf0ikDD

Create a bare repository on the VPS

I read the relevant section in the book ProGit to understand what a bare repository is.

$ mkdir remote.git
$ cd remote.git
$ git init --bare
Initialized empty Git repository in /home/git/remote.git/

Add remote repository to local repository

$ git remote add origin git@93.95.229.191:/home/git/remote.git

If this commands is printing errors, you can check what the origin is:

 git show-ref

Clone the repository from remote to local

git clone git@ip:/home/git/remote.git

You might have to checkout to main:

git checkout main

Source: https://git-scm.com/book/en/v2/Git-on-the-Server-Getting-Git-on-a-Server

Next

The instance was up, but repositories did not show up. I fixed this problem. I documented it there: https://yctct.com/cgit-permissions


personal computing command-line interface (cli) gnu linux trisquel shell literacy wiki cgit git devops

No affiliate links, no analytics, no tracking, no cookies. This work © 2016-2025 by yctct is licensed under CC BY-SA 4.0 .   about me   contact me   all entries & tags   FAQ   GPG public key

GPG fingerprint: 2E0F FB60 7FEF 11D0 FB45 4DDC E979 E52A 7036 7A88