添加用户

1
adduser git

拷贝秘钥

1
ssh-copy-id -i ~/.ssh/id_rsa  git@xx.xx.xx.xx

创建裸仓

1
cd /home/git && git init --bare milosmemo.git && chown -R git:git milosmemo.git

禁用shell登录

1
sed -i 's/\/home\/git:\/bin\/bash/\/home\/git:\/usr\/bin\/git-shell/' /etc/passwd

实现自动部署

1
2
3
4
5
cd /var/www && mkdir milosmemo && chown -R git:git milosmemo && cd /home/git/milosmemo.git/hooks && mv post-update.sample post-update && chmod +x post-update &&
cat <<EOF > post-update
git --work-tree=/var/www/milosmemo --git-dir=/home/git/milosmemo.git checkout -f
EOF