How to build a git server on a server

Source: Internet
Author: User
Tags version control system

Reference article:

Http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/ 00137583770360579bc4b458f044ce7afed3df579123eca000

Http://wlog.cn/soft/git-ssh-server-for-debian.html

In the Remote Warehouse section, we talked about the remote warehouse is actually not very different from the local warehouse, purely for 7x24 hours to boot and exchange changes.

GitHub is a remote repository that hosts open source code for free. But for some source code such as the life of the business company, neither want to open source code, but also reluctant to pay for the protection of GitHub, then you can only build a git server as a private warehouse use.

Building a git server requires a machine running Linux and is highly recommended for Ubuntu or Debian, so you can install it with a few simple apt commands.

Assuming you already have sudo access to the user account, below, formally start the installation.

First step, install git :

$ sudo apt-get install git

The second step is to create a git user to run the git service:

$ sudo adduser git

The third step is to create a certificate login:

Collect all the public keys of the users who need to log in, their own id_rsa.pub files, and import all the public keys into the /home/git/.ssh/authorized_keys file, one line at a.

The fourth step is to initialize the GIT repository:

First select a directory as the Git repository, assuming /srv/sample.git that the /srv command is entered in the directory:

$ sudo git init --bare sample.git

Git creates a bare repository with no workspaces, because the GIT repository on the server is purely for sharing, so the user is not allowed to log on to the server directly to the workspace, and the Git repositories on the server usually .git end up. Then, replace the owner with the git following:

$ sudo chown -R git:git sample.git

Fifth step, disable the shell login:

For security reasons, the GIT user created in the second step is not allowed to log in to the shell, which can be done by editing the /etc/passwd file. Find a line similar to the following:

git:x:1001:1001:,,,:/home/git:/bin/bash

Switch

git:x:1001:1001:,,,:/home/git:/usr/bin/git-shell

This way, git users can use git normally via SSH, but cannot log in to the shell because we git git-shell automatically exit each time a login is specified for the user.

Sixth step, clone the remote repository:

Now, you can git clone clone the remote repository by command and run it on your own computer:

$ git clone git@server:/srv/sample.gitCloning into ‘sample‘...warning: You appear to have cloned an empty repository.

The rest of the push is simple.

Managing Public keys

If the team is small, it is possible to collect everyone's public key and put it in the server's /home/git/.ssh/authorized_keys files. If the team has hundreds of people, it is not possible to play this way, then you can use gitosis to manage the public key.

Here we do not introduce how to play gitosis, hundreds of people's team are basically in the 500 strong, I believe that a high level of Linux administrator problem is not big.

Manage permissions

There are many companies that not only depend on the source code such as life, but also depending on the employees as thieves, will be in the version control system set up a set of comprehensive permissions control, each person has read and write access to each branch or even under each directory. Because Git was developed for Linux source code hosting, Git also inherits the spirit of the open source community and does not support permission control. However, because git supports hooks, it is possible to write a series of scripts on the server side to control the commit and so on, to achieve the purpose of permission control. Gitolite is the tool.

Here we also do not introduce gitolite, do not waste the limited life in the power struggle.

Summary
    • Building a git server is easy, usually in 10 minutes;

    • To facilitate the management of public key, with Gitosis;

    • To be as perverted as SVN to control permissions, with Gitolite.

In my actual construction process, if the operation of the fifth step, it is not even up. So I ignored the fifth step.

How to build a git server on a server

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.