ubuntu 22 搭建git服务

第一步,安装git

bash 复制代码
sudo apt-get install git

创建用户信息

bash 复制代码
git config --global user.name soft

第二步,创建一个git用户,用来运行git服务:

bash 复制代码
sudo adduser git

创建git仓库的存储目录、更改文件目录属主为代码仓库的管理者git,只让git用户对此目录有权限。

bash 复制代码
sudo mkdir /home/gitrepository
sudo chown git:git /home/gitrepository
sudo chmod 700 /home/gitrepository

默认状态下,gitosis会将git仓库放在 git用户的home下,所以我们做一个链接到/home /gitrepository

bash 复制代码
su git
ln -s /home/gitrepository /home/git/repositories
exit

第三步,创建证书登录:

方法1:

收集所有需要登录的用户的公钥,就是他们自己的id_rsa.pub文件,把所有公钥导入到/home/git/.ssh/authorized_keys文件里,一行一个。

bash 复制代码
su git
mkdir -p /home/git/.ssh/

方法2:Gitosis管理公钥

gitosis依赖于python工具库,先安装python工具库

bash 复制代码
sudo apt-get install python-setuptools

下载及安装

bash 复制代码
cd ~
git clone https://github.com/tv42/gitosis.git
cd gitosis
sudo python2.7 setup.py install

在服务端生成管理库:

bash 复制代码
sudo chmod -R 777 /home/git
sudo -H -u git gitosis-init < /tmp/id_rsa.pub
sudo chmod -R 755 /home/git

报错处理:IOError: [Errno 13] Permission denied: '/home/git/.ssh/authorized_keys.10768.tmp'

将/home/git及/home/git/.ssh权限都赋值为755,gitrepository也给个755(不能给777,不然要用绝对地址git@ip:/home/gitrepository/project,且不能通过gitosis管理)

执行上面命令后生成目录:

设置post-update脚本权限:

测试git服务器

新建测试工程

在/home/git/repositories建立新工程test

bash 复制代码
sudo mkdir test.git
cd test.git
sudo git init --bare
cd ..
sudo chown -R git:git test.git/

gitosis-admin克隆到本地

bash 复制代码
 git clone git@192.168.xxx.xxx:gitosis-admin

打开gitosis-admin/gitosis.conf, 添加test项目配置

上传gitosis-admin

测试拉下来test工程到本地

bash 复制代码
git clone git@192.168.xxx.xxx:test
相关推荐
小喻yushi1 分钟前
Git入门
git
python百炼成钢4 分钟前
52.Linux PWM子系统
linux·运维·服务器·驱动开发
CheungChunChiu6 分钟前
Linux 总线模型与 bind/unbind 完整解析
linux·ubuntu·sys·bind/unbind
可可苏饼干11 分钟前
ELK(Elastic Stack)日志采集与分析
linux·运维·笔记·elk
大柏怎么被偷了23 分钟前
【Git】基本操作
linux·运维·git
小女孩真可爱23 分钟前
大模型学习记录(八)---------RAG评估
linux·人工智能·python
我在人间贩卖青春39 分钟前
查看文件相关命令
linux·查看文件
番茄你个西红41 小时前
安装KingbaseES时服务器swap的设置
linux·数据库
python百炼成钢1 小时前
50.linux_USB驱动
linux·运维·服务器·驱动开发
jay2 小时前
ens2f0 IP 远程连线,balance-alb 模式配置双网卡(ens2f0 + ens6f0)Bond,避免断网
linux·运维·服务器·网络·tcp/ip