centos上搭建git服务器

1、执行安装命令

yum install git

2、创建用户组

groupadd gitgroup

useradd gituser -g gitgroup

3、创建证书登陆(没有公钥,这步可以不做)

收集所有要登陆用户的公钥,公钥在id_rsa.pub文件中,我们把公钥保存到/home/git/.ssh/authorized_keys文件里,一行一个。 如果没有该文件,则创建它。

$ cd /home/git/

$ mkdir .ssh

$ chmod 755 .ssh

$ touch .ssh/authorized_keys

$ chmod 644 .ssh/authorized_keys

4、初始化Git仓库

首先我们选定一个目录作为Git仓库,假定是/home/gitrepo/lichunjie.git,在/home/gitrepo目录下输入命令:

$ cd /home

$ mkdir gitrepo

$ chown gituser:gitgroup gitrepo/

$ cd gitrepo

$ git init --bare lichunjie.git

Initialized empty Git repository in /home/gitrepo/lichunjie.git/

以上命令Git创建一个空仓库,服务器上的Git仓库通常都以.git结尾。然后,把仓库所属用户改为git:

$ chown -R gituser:gitgroup lichunjie.git

5、克隆仓库

$ git clone gituser@127.0.0.1:/home/gitrepo/lichunjie.git

Cloning into 'lichunjie'...

warning: You appear to have cloned an empty repository.

Checking connectivity... done.

127.0.0.1为 Git 所在服务器 ip ,你需要将其修改为你自己的 Git 服务 ip。

这样我们的 Git 服务器安装就完成。