Quick Start Git...login
Quick Start Git Tutorial
author:php.cn  update time:2022-04-11 13:44:34

Git server setup


In the previous chapter, our remote repository used Github. Github’s public projects are free, but if you don’t want others to see your project, you will need to pay.

At this time we need to build a Git server ourselves as a private warehouse.

Next we will 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 we Create a git user group and user to run the git service:

$ groupadd git
$ adduser git -g git

2. Create certificate login

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

If the file does not exist, create it:

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


3. Initialize the Git repository

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

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

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

The above command Git creates an empty warehouse. Git warehouses on the server usually end with .git. Then, change the user belonging to the warehouse to git:

$ chown -R git:git w3cschoolcc.git

4. Clone the warehouse

$ git clone git@192.168.45.4:/home/gitrepo/w3cschoolcc.git
Cloning into 'w3cschoolcc'...
warning: You appear to have cloned an empty repository.
Checking connectivity... done.

192.168.45.4 is the IP of the server where Git is located. You need to change it to your own Git service IP.

In this way, our Git server installation is completed. Next, we can disable the git user to log in through the shell. This can be done by editing the /etc/passwd file. Find a line similar to the following:

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

and change it to:

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

php.cn