(1)安装 Git
Linux 做为服务器端系统,客户端可以为Windows也可以是Linux系统,分别安装 Git
服务器端:
#sudo apt-get install git
安装完后,查看 Git 版本
[root@localhost ~]# git --version git version 2.1.4
(2)服务器端创建 git 用户,用来管理 Git 服务,并为 git 用户设置密码
[root@localhost home]# id git
id: git:无此用户
[root@localhost home]# useradd git //添加git用户
[root@localhost home]# passwd git //为用户git设置密码
(3)服务器端创建 Git 仓库
设置 /home/git/test.git 为 Git 仓库
然后把 Git 仓库的 owner 修改为 git
[root@localhost home]# mkdir -p git/test.git [root@localhost home]# git init --bare git/test.git Initialized empty Git repository in /home/git/test.git/ [root@localhost home]# cd git/ [root@localhost git]# chown -R git:git test.git/
(4)Linux客户端clone Git 仓库
然后从 Linux Git 服务器上 clone 项目:
$ git clone [email protected]:/home/git/test.git
如果SSH用的不是默认的22端口,则需要使用以下的命令(假设SSH端口号是7700):
$ git clone [email protected]:7700/home/git/test.git
(5) 禁止 git 用户 ssh 登录服务器
之前在服务器端创建的 git 用户不允许 ssh 登录服务器
编辑 /etc/passwd
找到:
git:x:502:504::/home/git:/bin/bash
修改为
git:x:502:504::/home/git:/bin/git-shell
此时 git 用户可以正常通过 ssh 使用 git,但无法通过 ssh 登录系统。
(有待进一步完善......)