Assuming you already have sudo access to the user account, below, formally start the installation.
First step, install git :
For Ubuntu or Debian
$ sudo apt-get install git
for Centos
更新一下 yum 源
yum list git 查看可安装版本
yum 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.
Build a git Linux server