Build the Git server under Linux

  • 2020-05-30 21:56:28
  • OfStack

It is well known that version of the system in the development environment is necessary, but we can put the code on the free hosting to the GitHub, if we don't willing to open the source code of the project, the company didn't want to pay to use, so we can build our 1 Git server, can use Gitosis to manage public key, or is more convenient.

Built environment:

Server CentOS6.6 + git (version 1.8.3.1)

Client Windows10 + git (version 2.11.1.windows.1)

1. Install Git software

Linux is the server side system, Windows is the client side system, and Git is installed respectively

Installation server:


[root@linuxprobe ~]# yum install -y git
[root@localhost ~]# git --version   // After installation, view  Git  version 
git version 1.8.3.1

Install client:

Download Git for Windows, address: https:// git-for-windows.github.io /

Once installed, you can use Git Bash as the command line client.


$ git --version
git version 2.11.1.windows.1    // After installation, view Git version 

Install Gitosis


[root@linuxprobe ~]# cd software/
[root@linuxprobe software]# git clone https://github.com/res0nat0r/gitosis.git
[root@linuxprobe software]# yum install python-setuptools -y
[root@linuxprobe software]# cd gitosis
[root@linuxprobe gitosis]# sudo python setup.py install

The following message appears to indicate that the installation was successful


 Using /usr/lib/python2.6/site-packages
 Finished processing dependencies for gitosis==0.2

2. Create git users on the server side to manage Git services


[root@linuxprobe ~]# id git   // To view git Does the user exist 
id: git: no such user
[root@linuxprobe ~]# useradd git
[root@linuxprobe ~]# echo "123" | passwd --stdin git
[root@linuxprobe ~]# su - git  // Switch to the git Under the user 

Configure the public key

Configure administrators on Windows. git server needs some administrators. Upload the developer machine's public key to the server, add the administrator of git server, and open the git command line


$ ssh-keygen -t rsa   //1 Press enter, no password is required 
~ scp ~/.ssh/id_rsa.pub git@192.168.34.184:~  // Copied to the git On the server 

4. Configuration gitosis

Use the git user and initialize the gitosis


[root@linuxprobe ~]# cd .ssh
[root@linuxprobe ~]# gitosis-init < ./id_rsa.pub
Initialized empty Git repository in /home/git/repositories/gitosis-admin.git/
Reinitialized existing Git repository in /home/git/repositories/gitosis-admin.git/
[root@linuxprobe ~]# chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update   // Add permissions 

On the Windows machine clone gitosis-admin to the admin host


$ git clone ssh://git@192.168.34.184:22/gitosis-admin.git
$ cd gitosis-admin
$ ls
$ gitosis.conf keydir

gitosis.conf: git Server configuration file

keydir: Store the client's public key

Configure the gitosis.conf file


$ vim gitosis.conf
[gitosis]

[group gitosis-admin]      # Group name 
members = yueyong@SHA2-001    # The group members 
writable = gitosis-admin     # The project name 

[group test]        // And here I've added "test" The project team , Upload a git The server 
members = yueyong@SHA2-001
writable = test

Create a local test warehouse on the Windows manager machine and upload it to the git server


$ git config --global user.name "Your Name"     // The first 1 The subsubmission requires setting personal information, setting the user name and mailbox 
$ git config --global user.email "email@example.com"
$ cd ~/repo 
$ mkdir test
$ git init
$ tocuh readme.txt

Submit to the remote server


$ git --version
git version 2.11.1.windows.1    // After installation, view Git version 
0

The server will automatically create the test repository


$ git --version
git version 2.11.1.windows.1    // After installation, view Git version 
1

5. Add other git user developers

Due to company development team number increasing, the private key to manually add developer/home/git /. ssh/authorized_keys more troublesome, through the above Windows management system of the machine 1 to collect other developers private key id_rsa. pub file, and then spread to the server, the configuration, user permissions for project, namely can pull and push the project from the remote warehouse, achieve common development.


$ git --version
git version 2.11.1.windows.1    // After installation, view Git version 
2

$ git add .
$ git commit -m "add zhangsan@SHA2-002 pub and update gitosis.conf"
$ git push repo master

After the push is completed, the newly added developers can carry out the development of the project, and the subsequent addition of personnel can be added in this way, and the developer can directly bring down clone of the warehouse.


$ git --version
git version 2.11.1.windows.1    // After installation, view Git version 
4

Error reporting problem: ERROR:gitosis serve main repository read access denied

According to the error, it can be seen that key is no problem, through screening, found that should not take this/home git/repositories/test git write full, git clone git@192.168.34.184: test. git

That's it.


Related articles: