下载安装Git
Git 是一款免费、开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目。
此实验以 CentOS 7.2 x64 的系统为环境,搭建 git 服务器。
安装依赖库和编译工具
安装依赖库
[root@localhost ~]# yum -y install curl-devel expat-devel gettext-devel \
openssl-devel zlib-devel
安装编译工具
[root@localhost ~]# yum -y install gcc perl-ExtUtils-MakeMaker
解压和编译
[root@localhost ~]# tar xzf git-2.10.0.tar.gz
[root@localhost ~]# cd git-2.10.0/
[root@localhost git-2.10.0]# make all prefix=/usr/local/git
[root@localhost git-2.10.0]# make install prefix=/usr/local/git
配置环境变量
[root@localhost ~]# vim /etc/bashrc
# 末尾添加
export PATH=$PATH:/usr/local/git/bin
[root@localhost ~]# source /etc/bashrc
[root@localhost ~]# git --version
git version 1.8.3.1
创建git账号密码
[root@localhost ~]# useradd -m cyj
[root@localhost ~]# passwd cyj
更改用户 cyj 的密码 。
新的 密码:
无效的密码: 密码未通过字典检查 - 过于简单化/系统化
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。
初始化git仓库并配置用户权限
创建git仓库并初始化
[root@localhost ~]# mkdir -p /data/repositories
[root@localhost ~]# cd /data/repositories/
[root@localhost repositories]# git init --bare test.git
初始化空的 Git 版本库于 /data/repositories/test.git/
配置用户权限
[root@localhost ~]# chown -R cyj:cyj /data/repositories/
[root@localhost ~]# chmod 755 /data/repositories/
更改用户的shell环境
[root@localhost ~]# which git-shell
/usr/bin/git-shell
[root@localhost ~]# vim /etc/passwd
# 为了安全起见,此用户只能登陆git-shell
cyj:x:1001:1001::/home/cyj:/usr/bin/git-shell
使用git
[root@localhost ~]# git clone cyj@192.168.1.1:/data/repositories/test.git/
成功~