Set up Git server details and set up git details
In the remote warehouse section, we talked about the fact that the remote warehouse is no different from the local warehouse. It is purely for 7x24 boot and everyone's modifications are exchanged.
GitHub is a free remote repository hosting open-source code. However, for some commercial companies whose visual source code, such as life, do not want to disclose the source code, but do not want to pay the protection fee to GitHub, so they can only build a Git server for use as a private repository.
To build a Git server, you need to prepare a Linux machine. We strongly recommend using Ubuntu or Debian.Apt command to complete the installation.
Suppose you already haveThe user account with sudo permissions, which is officially started to be installed below.
Step 1: Installgit:
$ sudo apt-get install git
Step 2: CreateGit user for runningGit service:
$ sudo adduser git
Step 3: Create a certificate to log on:
Collect the public keys of all users that need to log on, that is, their ownId_rsa.pub file to import all public keysOne row in the/home/git/. ssh/authorized_keys file.
Step 4: Initialize the Git Repository:
Select a directory as the Git repository. Assume that/Srv/sample. git, inRun the following command in the/srv directory:
$ sudo git init --bare sample.git
Git creates a bare repository without a work zone. Because the Git repository on the server is purely for sharing, users are not allowed to directly log on to the server to change the work zone, and the Git repository on the server usually usesThe end of. git. Then, change the ownergit:
$ sudo chown -R git:git sample.git
Step 5: Disable shell Logon:
For security reasons, the git user created in step 2 is not allowed to log on to the shell, which can be editedThe/etc/passwd file is complete. Find a line similar to the following:
git:x:1001:1001:,,,:/home/git:/bin/bash
Changed:
git:x:1001:1001:,,,:/home/git:/usr/bin/git-shell
In this way,Git users can use it through ssh normallyGit, but cannot log on to the shell, because weTheGit-shell automatically exits upon every login.
Step 6: clone a remote Repository:
Now, you can useThe git clone command clones the remote repository and runs it on your 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.
Manage public keys
If the team is small, collect everyone's public keys and place them on the serverThe/home/git/. ssh/authorized_keys file is feasible. If the team has hundreds of people, they won't be able to do that. In this case, you can use Gitosis to manage the public key.
Here we will not introduce how to use Gitosis. The team of hundreds of employees is basically in the top 500. I believe it is not a problem to find a high-level Linux administrator.
Manage Permissions
There are many companies that don't only regard the source code as life, but also regard employees as thieves. They will set up a complete set of permission control in the version control system, whether each person has the read/write permission is accurate to each branch or even each directory. Because Git is 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, you can write a series of scripts on the server to control the submission and other operations to achieve permission control. Gitolite is the tool.
Here we will not introduce Gitolite, and do not waste the limited life in the permission struggle.