31.5 轻量级管理的Git服务
轻量级管理的含义是不采用默认的稍嫌复杂的管理模式(远程克隆gitosis-admin库,修改并推送的管理模式),而是直接在服务器端通过预先定制的配置文件提供Git服务。这种轻量级管理模式,对于为某些应用建立快速的Git库服务提供了便利。
例如在使用备份工具Gistore进行文件备份时,可以用Gitosis架设轻量级的Git服务,可以在远程使用Git命令进行双机甚至是异地备份。
首先创建一个专用账号,并设置该用户只能执行gitosis-serve命令。例如创建账号gistore,通过修改/etc/ssh/sshd_config配置文件,实现限制该账号登录的可执行命令。
Match user gistore
ForceCommand gitosis-serve gistore
X11Forwarding no
AllowTcpForwarding no
AllowAgentForwarding no
PubkeyAuthentication yes
PasswordAuthentication no
上述配置信息告诉SSH服务器,凡是以gistore用户登录的账号,都将强制执行Gitosis的命令:gitosis-serve gistore。
然后,在该用户的主目录下创建一个配置文件.gitosis.conf(注意文件名前面的点号),如下:
[gitosis]
repositories=/etc/gistore/tasks
gitweb=yes
daemon=no
[group gistore]
members=gistore
map readonly=(.):\1/repo
上述配置的含义是:
只有用户gistore才能够访问/etc/gistore/tasks下的Git库。
版本库的名称需要变换,例如system库会变换为实际路径/etc/gistore/tasks/system/repo.git。