in the Remote Warehouse section, we talked about the remote repository is actually not very different from the local warehouse, purely for 7x24 hours to switch on and exchange everyone's 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.
Build Git The server needs to prepare a running Linux the machine, highly recommended Ubuntu or Debian , so that through a apt
few simple command to complete the installation.
Suppose you already have sudo
permissions of the user account, below, formally start the installation.
first step, install git
:
$ su
Do apt- Get Install git
The second step is to create a git
user, used to run git
Service:
$ su
Do adduser git
The third step is to create a certificate login:
Collect all the public keys of the users who need to log on, their own id_rsa.pub
file, import all the public keys into /home/git/.ssh/authorized_keys
the in the file, one line at a.
Fourth step, initialize Git Warehouse:
first select a directory as Git Warehouse, assuming it is /srv/sample.git
, in /srv
Enter the command in the directory:
$ su
Do git init--bare sample.git
Git a bare repository is created, and the bare repository does not have a workspace because the server Git warehouses are purely for sharing, so users are not allowed to log on directly to the server to change workspaces, and the server Git warehouses are usually .git
end. Then, Replace the owner with the git
following:
$ su
Do chown-r git:git sample.git
Fifth Step, disable Shell Login:
for security reasons, the second step creates a git user not allowed to log in Shell , this can be done by editing /etc/passwd
The file is complete. 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
The user can normally pass SSH Use git , but cannot log on Shell , because we are git
user-specified git-shell
automatically exits every time you log in.
Sixth step, clone the remote repository:
now, you can use git clone
The command clones the remote repository and runs on its own computer:
git clone git
@server :/srv/sample.git
Cloning 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, collect everyone's public key and put it in the server's /home/git/.ssh/authorized_keys
the document is feasible. 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.
We don't show you how to play here . gitosis , hundreds of people in the team are basically - Strong, believe in finding a high-level Linux The administrator has little problem.
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.
we don't even introduce it here . Gitolite , don't waste your limited life in the power struggle.
Summary
· Building A Git server is very simple, usually ten minutes to complete;
· to facilitate the management of public key, with gitosis;
· to be as perverted as SVN to control permissions, with Gitolite.
git24--Build a git server