搭建无限制权限的简单git服务器使用git-daemon脚本

如果想要用ubantu架设无限制权限(即不适用gitosis)的简单git服务器,实现git库下载clone,push等简单的基本功能,

可以直接使用git-daemon脚本(非常不安全,建议项目代码的git管理不要使用!

本地安装完sudo apt-get install git git-core之后没有安装git-daemon-run或者git-daemon-sysvinit时,可以执行如下操作:

sudo vi /etc/init.d/git-daemon

==========================================CP下面的代码复制过去,修改下base-path和user==================================

#! /bin/sh

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

NAME=git-daemon
PIDFILE=/var/run/$NAME.pid
DESC="the git daemon"
DAEMON=/usr/lib/git-core/git-daemon
DAEMON_OPTS="--base-path=/home/dongwuming/git --enable=receive-pack --export-all --verbose --syslog --detach --pid-file=$PIDFILE --user=dongwuming --group=nogroup"

test -x $DAEMON || exit 0

[ -r /etc/default/git-daemon ] && . /etc/default/git-daemon

. /lib/lsb/init-functions

start_git() {
  start-stop-daemon --start --quiet --pidfile $PIDFILE \
    --startas $DAEMON -- $DAEMON_OPTS
}

stop_git() {
  start-stop-daemon --stop --quiet --pidfile $PIDFILE
  rm -f $PIDFILE
}

status_git() {
  start-stop-daemon --stop --test --quiet --pidfile $PIDFILE >/dev/null 2>&1
}

case "$1" in
  start)
  log_begin_msg "Starting $DESC"
  start_git
  log_end_msg 0
  ;;
  stop)
  log_begin_msg "Stopping $DESC"
  stop_git
  log_end_msg 0
  ;;
  status)
  log_begin_msg "Testing $DESC: "
  if status_git
  then
    log_success_msg "Running"
    exit 0
  else
    log_failure_msg "Not running"
    exit 1
  fi
  ;;
  restart|force-reload)
  log_begin_msg "Restarting $DESC"
  stop_git
  sleep 1
  start_git
  log_end_msg 0

  ;;
  *)
  echo "Usage: $0 {start|stop|restart|force-reload|status}" >&2
  exit 1
  ;;
esac

exit 0

======================================:wq!保存退出=============================================

sudo chmod 777  /etc/init.d/git-daemon

sudo /etc/init.d/git-daemon stop
sudo /etc/init.d/git-daemon start

ps -ef | grep git-daemon
1000      6100     1  0 17:01 ?        00:00:00 /usr/lib/git-core/git-daemon --base-path=/home/dongwuming/git --enable=receive-pack --export-all --verbose --syslog --detach --pid-file=/var/run/git-daemon.pid --user=dongwuming --group=nogroup
1000      6243 17377  0 17:29 pts/2    00:00:00 grep --color=auto git-daemon

OK 用另外一台局域网的机器

git clone git://192.168.xx.xx/your-bare-or-mirror-git-repositories【建库的时候一定要是一个bare赤裸的或者mirror镜像的git库】

cd your-bare-or-mirror-git-repositories

vi test

just a test!

git add.;git commit -m "just a test"

git push origin HEAD:master

Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 281 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To git://192.168.50.125/test
   6ca6f70..9b97ad9  master -> master

OK了

git-daemon中控制用户可以PUSH的权限的参数为:

--enable=receive-pack

 ====================================UBANTU sudo apt-gt install git-daemon=========================================

直接下载git-daemon 来管理git

$apt-get install git git-core git-daemon-run


 配置git-daemon-run

$vi /etc/sv/git-daemon/run

====================

#!/bin/sh
exec 2>&1
echo 'git-daemon starting.'
exec chpst -m64000000 /

git-daemon --verbose --base-path=/var/cache/git /var/cache/git --enable=receive-pack --export-all --verbose --syslog --detach 【根据个人需求修改配置】

 

 

启动git-daemon

$sudo sv stop git-daemon

$sudo sv start git-daemon

 

 

你可能感兴趣的:(Daemon)