环境:ubuntu16.4
一.后台服务搭建
1.以root用户登陆Linux后台,执行下面的命令安装git
$ apt install git
2.创建git用户
$ adduser git
3.创建仓库目录
$ su - git
$ mkdir -p repository/myself.git
4.初始化仓库
$ cd ~/repository
git@ubuntu:~/repository$ git init --bare myself.git
Initialized empty Git repository in /home/git/repository/myself.git/
5.禁用shell登陆
处于安全考虑,需要禁止git用户ssh登陆
root@ubuntu:/home# chsh git
Changing the login shell for git
Enter the new value, or press ENTER for the default
Login Shell [/bin/bash]: /usr/bin/git-shell
修改git用户的shell为git-shell后,git用户可以正常通过ssh使用git,但无法ssh登陆。
6.克隆远程仓库
$ git clone git@IP:/home/git/repository/myself.git
目录下会生成myself目录
7.提交文件
在myself目录下创建一个readme.txt文件用来测试
$ git add test.py
$ git commit -m "first commit"
[master 316749f] first commit
1 file changed, 7 insertions(+)
create mode 100644 test.py
$ git push
git@192.168.233.130's password:
Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 345 bytes | 172.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To 192.168.233.130:/home/git/repository/myself.git
5155385..316749f master -> master