GIT系列之GIT服务器搭建

git服务器简单搭建

以下操作以CentOS6.8为例

git 安装

yum install git

git 服务器打搭建

  • 创建用户和用户组
groupadd git
adduser git -g git
  • 创建authorized_keys文件
mkdir /home/git/.ssh
chmod 700 /home/git/.ssh
touch /home/git/.ssh/authorized_keys
chmod 600 /home/git/.ssh/authorized_keys
chown -R git:git git
  • 客户端创建密钥并上传
ssh-keygen -t rsa -C "your_email"

该命令会产生两个文件: id_rsa对应私钥,id_rsa.pub对应公钥。将id_rsa.pub中的内容写到服务器的authorized_keys文件中。如果有多个客户端,那么在authorized_keys文件中,一行保存一个客户端的公钥。

  • 创建git仓库
mkdir gitrepo
chown git:git gitrepo
cd gitrepo
git init --bare sample.git
chown -R git:git sample.git 

到此,git服务器搭建完毕。

  • 客户端Clone
git clone git@your_gitServer_ip:/home/gitrepo/sample.git 
  • 同步代码库代码到WEB目录
cd /home/gitrepo/sample.git/hooks/
vi post-receive
输入
#!/bin/bash
git --work-tree=/data/wwwroot checkout -f

猜你喜欢

转载自blog.csdn.net/qq_33261700/article/details/79580029