1,安裝Git所需依賴包
????# yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
????# yum install gcc perl-ExtUtils-MakeMaker
2,卸載CentOS自帶的git
????# yum remove git
3,下載較新Git版本
????# mkdir /usr/src/tools
????# cd /usr/src/tools
????# wget https://www.kernel.org/pub/software/scm/git/git-2.9.5.tar.gz
????# tar -zxvf git-2.9.5.tar.gz
4,安裝Git并添加到環(huán)境變量中,Git安裝路徑為/usr/local/git
????# cd git-2.9.5
????# make prefix=/usr/local/git all
????# make prefix=/usr/local/git install
????# echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/bashrc
????# source /etc/bashrc
????完畢,查看git版本號(hào)
????# git --version
5,創(chuàng)建用戶git,用來(lái)運(yùn)行Git服務(wù)
# adduser git
# usermod -G git git
# su git
# cd /home/git/
# mkdir .ssh
# cd .ssh
# touch authorized_keys
# chmod 700 /home/git/.ssh
# chmod 600 home/git/.ssh/authorized_keys
在git用戶的home目錄(/home/git/)創(chuàng)建一個(gè).ssh的目錄,將協(xié)同工作人員的SSH公鑰添加到該目錄的authorized_keys文件中。
6,收錄客戶端的SSH公鑰到/home/git/.ssh/authorized_keys文件中
????客戶端使用命令 ssh-keygen -t rsa -C "你的email地址" ,會(huì)在~/.ssh/id_rsa.pub生成SSH公鑰,復(fù)制給管理員即可。
7,配置服務(wù)器端ssh服務(wù)
????# vim /etc/ssh/sshd_config
????找到以下三段并去掉前面的#號(hào)
????RSAAuthentication yes
????PubkeyAuthentication yes
????AuthorizedKeysFile /home/git/.ssh/authorized_keys? #你的authorized_keys所在路徑
8,初始化git倉(cāng)庫(kù)(裸庫(kù))
????# cd /home/git
????# mkdir repositories
????# cd repositories/
????# mkdir project.git
????# git init --bare project.git
????# chown -R git:git project.git/
9,禁用git用戶shell登錄
????# vim /etc/passwd
????git:x:1001:1001:,,,:/home/git:/bin/bash
????改為
????git:x:501:501::/home/git:/bin/bash