快速搭建git私有服务器

为什么要搭建git私有服务器?GitHub不好用吗?GitHub当然是很好用的,但是私有仓库收费啊,我们有一些代码代码不想被别人看到,例如你研究出来的某个0day的exp,或者别的商业项目,是不可能放在github公开的,且不说私有仓库的费用问题,那也是在别人的服务器上啊。所以最好的建议还是搭建自己的git私有服务器。

1
sudo apt install git
1
2
adduser git
passwd git

为了安全考虑,建议禁用git用户shell登陆,通过编辑/etc/passwd完成。将类似下面这行:

git❌1001:1001:,,,:/home/git:/bin/bash

改为

git❌1001:1001:,,,:/home/git:/usr/bin/git-shell

这样的好处是可以正常的通过ssh使用git,而不需要登陆shell,因为git-shell指定每次登陆就自动退出。

1
2
3
mkdir -p /home/git/test.git
git init --bare /home/git/test.git
chown -R git:git /home/git/test.git // 修改仓库的owner为git
  1. git的url:ssh://git@xx.xx.xx.xx:22
  2. git的用户名:git
  3. git的密码:上面passwd git修改的密码
  4. test仓库的url:ssh://git@xx.xx.xx.xx:22/home/git/test.git
1
2
3
4
5
6
7
git config --global user.email "ssh://git@xx.xx.xx.xx:22"
git config --global user.name "git"
git clone ssh://git@xx.xx.xx.xx:22/home/git/test.git
touch readme
git add readme
git commit readme -m "readme"
git push