• In the section on remote repositories, we explained that remote repositories are actually no different from local repositories, purely for 7×24 hours to boot and exchange everyone’s changes.
  • GitHub is a remote repository that hosts open source code for free. However, for some commercial companies that regard source code as life, and do not want to disclose the source code, and do not want to pay the protection fee to GitHub, they can only build a Git server as a private repository.
  • Git server setup requires a machine running Linux, Ubuntu or Debian is highly recommended, with a few simple apt commands to complete the installation.
  • Assuming you already have a sudo user account, the installation begins.
  • The first step is installationgit:
$ sudo apt-get install git
Copy the code
  • Step 2: Create a git user to run git services:
$ sudo adduser git
Copy the code
  • Step 3: Create certificate login:
  • Collect the public keys of all users who need to log in, their ownid_rsa.pubFile to import all public keys into/home/git/.ssh/authorized_keysIn the file, one line at a time.
  • Step 4 initialize Git repository:
  • Start by selecting a directory as your Git repository, assuming it is/srv/sample.gitIn the/srvEnter the command in the directory:
$ sudo git init --bare sample.git
Copy the code
  • Git creates a bare repository, which has no workspace. Because the Git repository on the server is purely for sharing, users are not allowed to log in directly to the server to change the workspace, and Git repositories on the server are usually used as.gitAt the end. Then,ownerInstead ofgit:
$ sudo chown -R git:git sample.git
Copy the code
  • Step 5: DisableshellLogin:
  • For security reasons, the Git user created in step 2 is not allowed to log into the shell, which can be edited/etc/passwdFile completed. Find a line like the following:
git:x:1001:1001:,,,:/home/git:/bin/bash
Copy the code
  • To:
git:x:1001:1001:,,,:/home/git:/usr/bin/git-shell
Copy the code
  • In this way, git users can pass throughsshUse git but can’t log in to the shell because we specified it for git usersgit-shellEvery time you log in, you automatically log out.
  • Step 6, clone the remote repository:
  • Now, you can passgit cloneCommand to clone remote repository, run on respective computers:
$ git clone git@server:/srv/sample.git
Cloning into 'sample'. warning: You appear to have cloned an empty repository.Copy the code

The rest of the push is easy.

Management of public key

  • If the team is small, collect everyone’s public keys and put them on the server/home/git/.ssh/authorized_keysIt’s in the files. If you have hundreds of people on your team, you can’t do this, so you can use Gitosis to manage public keys.
  • Here we do not introduce how to play Gitosis, hundreds of people’s team are basically in the top 500, I believe that finding a high-level Linux administrator is not a big problem.

Administrative privileges

Many companies that treat their source code like life and their employees like thieves have a complete set of permissions built into their version control systems, where everyone has access to and from every branch or even every directory. Because Git was developed for Linux source hosting, it also inherits the spirit of the open source community and does not support permission control. However, because Git supports hooks, you can write a series of scripts on the server side to control the commit and other operations to achieve permission control purposes. Gitolite was that tool.

Let’s not introduce Gitolite here either. Don’t waste your limited life in a power struggle.

summary

Setting up a Git server is very simple, usually in 10 minutes.

To facilitate the management of public keys, use Gitosis;

To control permissions as perverted as SVN, use Gitolite.