Coding With Fun
Home Docker Django Node.js Articles FAQ

Git server build


May 25, 2021 Git


Table of contents


Git server build

In the previous section, we used Github in our remote repository, and the items that Github exposes are free, but you'll be charged if you don't want others to see your project.

At this point, we need to build our own Git server for use as a private repository.

Next we'll use Centos as an example to build a Git server.

1, install Git

$ yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel
$ yum install git

Next, let's create a git user group and user to run the git service:

$ groupadd git
$ adduser git -g git

2, create a certificate login

Collect the public keys of all users who need to log in, which are located in the id_rsa.pub file, and import our public keys into the /home/git/.ssh/authorized_keys file, one line at a time.

If you don't have the file to create it:

$ cd /home/git/
$ mkdir .ssh
$ chmod 700 .ssh
$ touch .ssh/authorized_keys
$ chmod 600 .ssh/authorized_keys

3, initialize Git warehouse

First we select a directory as the Git repository, assuming it is /home/gitrepo/w3cschoolcn.git, and enter the command in the /home/gitrepo directory:

$ cd /home
$ mkdir gitrepo
$ chown git:git gitrepo/
$ cd gitrepo

$ git init --bare w3cschoolcn.git
Initialized empty Git repository in /home/gitrepo/w3cschoolcn.git/

The above command Git creates an empty repository, and the Git repository on the server usually ends with .git. Then, change the user who owns the repository to git:

$ chown -R git:git w3cschoolcn.git

4, clone warehouse

$ git clone [email protected]:/home/gitrepo/w3cschoolcn.git
Cloning into 'w3cschoolcn'...
warning: You appear to have cloned an empty repository.
Checking connectivity... done.

192.168.45.4 is the server ip where Git is located, and you need to modify it to your own Git service ip.

So our Git server installation is complete, and then we can disable the git user login via shell, which can be done by editing/etc/passwd file. F ind a line like this:

git:x:503:503::/home/git:/bin/bash

Replace with:

git:x:503:503::/home/git:/sbin/nologin