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