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
相关推荐
likfishdn15 分钟前
Linux的文件与目录管理
linux·运维·服务器
2501_9032386526 分钟前
Git Bash:Windows下的强大命令行工具
windows·git·bash·个人开发
chian-ocean35 分钟前
Linux 文件缓冲区:高效数据访问的幕后推手
linux·运维·服务器
加油=^_^=36 分钟前
【Linux】进程优先级 | 进程调度(三)
linux·运维·服务器
若云止水1 小时前
Ubuntu 下 nginx-1.24.0 源码分析 - ngx_init_cycle 函数 - 详解(4)
数据库·nginx·ubuntu
吃汤圆的抹香鲸1 小时前
GoLand 安装包 绿色版 Win,Mac,Linux 包含IntelliJ全家桶 专为Go语言设计的集成开发环境(IDE)
linux·windows·macos·go·intellij-idea·go1.19
追寻光1 小时前
Cannot find a valid baseurl for repo: base/7/x86_64
linux
元气满满的热码式1 小时前
Docker数据卷操作实战
linux·运维·docker·云原生·容器
陆沙1 小时前
deepseek-r1-centos-本地服务器配置方法
linux·服务器·centos
吃汤圆的抹香鲸2 小时前
Rider 安装包 绿色版 Win/Mac/Linux 适合.NET和游戏开发者使用 2025全栈开发终极指南:从零配置到企业级实战
linux·运维·windows·sql·游戏·macos·.net