当前位置: 首页 > 工具软件 > space-daemon > 使用案例 >

极简的Git服务器:git-daemon

包谭三
2023-12-01

git-daemon是Git软件包中内置的Git服务器。 这是一个极简的Git服务器,没有权限控制,也没有Web控制台。 但是不需要安装额外的Git服务器,安装和使用非常方便,适合局域网内使用。 本文介绍如何在Archlinux下使用git-daemon。

Git-daemon 文档: https://git-scm.com/docs/git-daemon

启动Git服务器文档: https://git-scm.com/book/ch4-4.html

安装git-daemon

安装git软件包,git-daemon就会随之安装。

# Archlinux
yaourt -S git
# Ubuntu
sudo apt-get install git git-core

创建Git目录

在创建Git服务目录前,需要创建一个git用户。

sudo adduser git

然后切换到git用户,并进行Git服务目录的创建和配置。

su git
mkdir /srv/git/my-first-repo.git
cd /srv/git/my-first-repo.git
git init --bare

因为git-daemon不提供任何权限验证,所以默认不允许用户push。 我们只在局域网内使用,因此可以开启它:

su git
cd /srv/git/my-first-repo.git
git config daemon.receivepack true

配置SSH Key

我们希望通过SSH方式来进行Git访问, 只需把你的公钥添加到git用户的 authorized_keys下即可。

首先创建该配置文件( /home/git/.ssh/authorized_keys):

su git
cd
mkdir .ssh && chmod 700 .ssh
touch .ssh/authorized_keys && chmod 600 .ssh/authorized_keys

然后修改 authorized_keys,在其中新的一行插入你的公钥。 默认公钥文件名是 ~/.ssh/id_rsa.pub

启动Git服务

在采用systemd服务管理器的Linux发行版中,通过 systemctl启动git-daemon:

# 立即启动
sudo systemctl start git-daemon.socket
# 开机启动
sudo systemctl enable git-daemon.socket

如果没看到错误的话Git服务器已经启动啦! 可以通过 systemctl status git-daemon.socket来查看启动状态。

Clone and Push!

现在就可以使用该Git服务了!现在克隆一下前面创建的仓库: /srv/git/my-first-repo.git

git clone git@192.168.1.32:/srv/git/my-first-repo.git

假设你的git-daemon所在机器IP为 192.168.1.32

http://www.xcszxyy.cn/e/space/?userid=354007?feed_filter=ij&mi20160617=&42.html
http://www.xcszxyy.cn/e/space/?userid=354008?feed_filter=kp&fp20160617=&14.html
http://www.xcszxyy.cn/e/space/?userid=354009?feed_filter=ep&vf20160617=&73.html
http://www.xcszxyy.cn/e/space/?userid=354010?feed_filter=el&ju20160617=&81.html
http://www.xcszxyy.cn/e/space/?userid=354011?feed_filter=di&ey20160617=&71.html
http://www.xcszxyy.cn/e/space/?userid=354012?feed_filter=dt&qv20160617=&35.html
http://www.xcszxyy.cn/e/space/?userid=354013?feed_filter=tw&hx20160617=&44.html
http://www.xcszxyy.cn/e/space/?userid=354014?feed_filter=hx&md20160617=&31.html
http://www.xcszxyy.cn/e/space/?userid=354015?feed_filter=co&in20160617=&23.html
http://www.xcszxyy.cn/e/space/?userid=354016?feed_filter=ca&pj20160617=&70.html
http://www.xcszxyy.cn/e/space/?userid=354017?feed_filter=tp&dk20160617=&31.html
http://www.xcszxyy.cn/e/space/?userid=354018?feed_filter=lq&zc20160617=&29.html
http://www.xcszxyy.cn/e/space/?userid=354019?feed_filter=yd&hh20160617=&28.html

如果你的 ~/.ssh/id_rsa.pub已经添加到了服务器的 /home/git/.ssh/.authorized_keys, 那么下面的push操作也会成功:

git commit -m 'test' --allow-empty
git push origin master
 类似资料: