搭建git服务器

以下都在centos7环境下:

第一步,安装git

$ yum install git

第二步,新增git用户

$ adduser git
$ passwd git
>键入密码

第三步,采集登陆用户的公钥id_rsa.pub,导入至/home/git/.ssh/authorized_keys中,

其中先进入git用户路径下(/home/git),然后创建

$ mkdir ./.ssh && cd ./.ssh && vim authorized_keys

第四步,初始化git仓库,假定仓库是/home/git/MyRepository.git,

# 先要创建仓库
$ mkdir /home/git/MyRepository.git
$ git init --bare MyRepository.git # 初始化仓库,在/home/git 路径下键入

修改owner

$ chown -R git:git MyRepository.git

  

第五步,出于安全考虑,第二步创建的git用户不允许登录shell,这可以通过编辑/etc/passwd文件完成。找到类似下面的一行

git:x:1001:1001::/home/git:/bin/bash
修改为
git:x:1001:1001::/home/git:/usr/bin/git-shell

  

第六步,克隆远程仓库

$ git clone git@server:/home/git/MyRepository.git

  

然后在自己clone下项目后,发现push 报错

$ git add file

$ git commit -m "this is"

$ git push

$ git pull

权限不够导致,第四步很关键。

原文地址:https://www.cnblogs.com/zenan/p/9930843.html