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
相关推荐
gd63213741 小时前
银河麒麟 aarch64 linux 里面的 qt 怎么安装kit
linux·服务器·qt
A-花开堪折1 小时前
Qemu 嵌入式Linux驱动开发
linux·运维·驱动开发
磊灬泽1 小时前
【Linux驱动开发】PWM子系统-servo
linux·运维·算法
郝学胜-神的一滴2 小时前
Linux系统函数stat和lstat详解
linux·运维·服务器·开发语言·c++·程序人生·软件工程
Mr.亮先生2 小时前
常用、高效、实用的 Linux 服务器监控与运维工具清单
linux·运维·服务器
poemyang3 小时前
单线程如何撑起百万连接?I/O多路复用:现代网络架构的基石
linux·rpc·i/o 模式
222you3 小时前
Git的diff命令
git
鹿鸣天涯3 小时前
Wine 10.15 发布!Linux 跑 Windows 应用更丝滑了
linux·运维·windows
Better Bench4 小时前
ubuntu20.04安全的安装可穿墙的远程软件parsec
安全·ubuntu·远程·parsec
补三补四4 小时前
Git 基础操作指南
大数据·git·elasticsearch