linux搭建Git服务器(详细步骤)

本文详细介绍了如何在Linux环境下从零开始搭建Git服务器,包括Git的安装、SSH密钥的生成、Git用户账户的创建、仓库目录的设定、Python setuptool的安装、gitosis的获取与配置等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

第一步:安装git

[root@localhost /]# yum install -y git

安装完成后,查看git版本

[root@localhost /]# git --version

git version 1.8.3.1

这样Git 就安装完成了!

第二步:创建公钥和秘钥

[root@localhost /]# ssh-keygen -t rsa

第三步:创建git管理账户

[root@localhost /]# cd /home

[root@localhost /home]# useradd git  // 创建账户

[root@localhost /home]# passwd git   // 设置密码

第四步:创建git仓库存放目录,以后所有仓库都将放在该目录方便管理

[root@localhost /]# mkdir /home/git/repositories

[root@localhost /]# chown git:git /home/git/repositories // 设置仓库目录所有者为git

[root@localhost /]# chmod 755 /home/git/repositories // 设置仓库目录权限

第五步:安装Python的setup tool

[root@localhost /]# yum install python-setuptools

第六步:获取gitosis 并利用Python 的 setup tool 安装

[root@localhost /]# cd /tmp // 进入tmp目录

[root@localhost /]# git clone https://github.com/res0nat0r/gitosis.git // 获取gitosis

[root@localhost /]# cd gitosis // 进入

[root@localhost /]# sudo python setup.py install // 执行安装 等待安装完成

第七步:配置gitosis

[root@localhost /]# cp ~/.ssh/id_rsa.pub /tmp    // 将公钥复制到tmp目录

[root@localhost /]# sudo -H -u git gitosis-init < /tmp/id_rsa.pub    // 初始化 gitosis

[root@localhost /]# chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update // 设置权限

第八步:管理gitosis

[root@localhost /]# cd /home/git 进入home目录

[root@localhost /home/git]# git clone git@127.0.0.1/gitosis-admin.git 拉去gitosis 自动创建的一个仓库

[root@localhost /home/git]# cd gitosis-admin/ 进入该目录

    说明:gitosis-admin 里面会有一个文件一个目录分别是:gitosis.config,keydir,keydir 该文件是用来存放.pub公钥的。(只有要将公钥放在keydir下,就可以拉去相关授权的仓库了)

gitosis.config是用来管理仓库和用户的,如下图所示:

[gitosis]

[group gitosis-admin]
// 管理用户(多个用户只需继续往后面添加)
members = root@localhost xiaoliu
// 管理仓库 (多个仓库只需继续往后面添加)
writable = gitosis-admin

[group test]
// 公钥文件名字
members = test test2 
// 仓库名字
writable = test demo1 demo2 demo3

 

  这样就大工告成了

 

 有问题可在下发留言指出,共同学习,共同交流

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值