centos7.0 下安装git(ssh方式)

最近刚弄了个阿里云,在上面弄个git服务器,这里只弄了ssh方式访问,http方式访问的可以看我另外一个随笔http://www.cnblogs.com/hz-cww/p/6077970.html

1、 安装依赖的库

[root@localhost ~]# yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel

2、 删除原本的安装的git

[root@localhost ~]# yum remove git -y

3、下载git-2.10.0.tar.gz 到 /usr/local/src

[root@localhost ~]# cd /usr/local/src
[root@localhost src]# wget https://www.kernel.org/pub/software/scm/git/git-2.10.0.tar.gz

4、 编译安装

[root@localhost src]# tar -zvxf git-2.10.0.tar.gz
[root@localhost src]# cd git-2.10.0
[root@localhost src]# make prefix=/usr/local/git all
[root@localhost src]# make prefix=/usr/local/git install

5、 增加软连接

[root@localhost src]# ln -s /usr/local/git/bin/* /usr/bin/
[root@localhost src]# git --version

如果能正常显示版本号,即表示成功

6、新建git用户和设置密码

[root@localhost ~]# useradd -m git
[root@localhost ~]# passwd git

7、新建git的仓库,并设置权限,我这边是建立repositories这个文件夹

[root@localhost ~]# mkdir -p /home/git/repositories
[root@localhost ~]# chown -R git:git /home/git/repositories
[root@localhost ~]# chmod 755 /home/git/repositories

8、切换到git用户下,新建仓库

[root@localhost ~]# su git
[git@localhost root]$ mkdir /home/git/repositories/test.git
[git@localhost root]$ cd /home/git/repositories/test.git
[git@localhost test.git]$ git --bare init

ok,到这里简单的git服务器已经建立好了,你可以去客户端机子上clone了

地址:ssh://git@这里写你的IP/home/git/repositories/test.git

9、禁用git用户的shell登陆,修改/etc/passwd文件

[root@localhost ~]# vi /etc/passwd

找到这一行

git:x:1001:1001:,,,:/home/git:/bin/bash
将最后一个冒号后改为:
git:x:1001:1001:,,,:/home/git:/usr/src/git-2.10.0/git-shell
这样,git用户可以正常通过ssh使用git,但无法登录shell,因为我们为git用户指定的git-shell每次一登录就自动退出。

10、附加:下一次新建git仓库时,shell只能用root登录

[root@localhost root]$ mkdir /home/git/repositories/test2.git
[root@localhost root]$ cd /home/git/repositories/test2.git
[root@localhost test.git]$ git --bare init

这里新建完之后,必须将新建的git仓库更改所有者为git用户,不然无法连接,执行下面命令,

注意这里-R必须加上,不然git用户clone会出现权限不够问题

[root@localhost ~]# chown -R git:git /home/git/repositories

ok,到这里就基本搞定。

 

 

转载于:https://www.cnblogs.com/hz-cww/p/6065596.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值