服务器信息:
IP : 10.16.59.160 内网

一、安装GIT服务器

yum install git
git --version 安装后查看下天版本,就这么简单.

二、创建GIT账户

adduser gituser
禁止用户git用户进行SSH登录
使用git-shell替换bash ,这样gituser用户就不能通过ssh登录
chsh -s $(command -v git-shell) git
或者:
vim /etc/passwd
gituser:x:32324:32324::/home/gituser:/bin/bash 改为
gituser:x:32324:32324::/home/gituser:/usr/bin/git-shell

三、创建服务器仓库

mkdir -p /data/githourse/
cd /data/githourse/
git init --bare gitone.git
chown -R gituser:gituser gitone.git
到这来GIT服务器就搭建好了.
mkdir /home/gituser/.ssh
touch /home/gituser/.ssh/authorized_keys  (这个文件稍后来存储客户端的公钥,做免密码登录用)

四、客户端

链接服务器:
git clone gituser@10.16.59.160:/data/githouse/gitone.git
第一次clone会出现如下问题

Initialized empty Git repository in /home/duchaoqun/testgit/gitone/.git/
The authenticity of host '10.16.59.160 (10.16.59.160)' can't be established.
RSA key fingerprint is e5:bb:14:17:40:13:75:39:ae:42:b6:b6:e7:97:7c:a6.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.16.59.160' (RSA) to the list of known hosts.

此处会提示权限问题.
接下来我们手动创建rsa授权.

ssh-keygen -t rsa -C "394534000@qq.com"

此模块会在 ~/.ssh/ 下生成一个公钥和私钥,

id_rsa       id_rsa.pub
把id_rsa.pub内容拷贝到 /home/gituser/.ssh/authorized_keys 内

OK到此即可.
在客户端,再次进行
git clone gituser@10.16.59.160:/data/githouse/gitone.git ~~哈哈OK了