以Linux centos6.5为服务器
服务端:
查看git版本,没有git先安装git
[tony@localhost home]$ git --version
git version 2.3.0
服务器端创建 git 用户,用来管理 Git 服务,并为 git 用户设置密码
[tony@localhost home]$ id git
id: git: No such user
[tony@localhost home]$ useradd git
bash: /usr/sbin/useradd: Permission denied
权限不够切换到root用户
[tony@localhost home]$ su
Password:
[root@localhost home]# id git
id: git: No such user
[root@localhost home]# useradd git
[root@localhost home]# passwd git
Changing password for user git.
New password:
BAD PASSWORD: it is too simplistic/systematic
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication tokens updated successfully.
[root@localhost home]# id git
uid=501(git) gid=501(git) groups=501(git)
服务器端创建 Git 仓库
设置 /home/data/git/gittest.git 为 Git 仓库
然后把 Git 仓库的 owner 修改为 git
[root@localhost home]# mkdir -p data/git/gittest.git
[root@localhost home]# git init --bare data/git/gittest.git
Initialized empty Git repository in /home/data/git/gittest.git/
[root@localhost home]# cd data/git
[root@localhost git]# chown -R git:git gittest.git
查看本机ip地址,这里是192.168.2.183
[tony@localhost git]$ ifconfig
eth1 Link encap:Ethernet HWaddr 00:0C:29:25:D7:58
inet addr:192.168.2.183 Bcast:192.168.2.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe25:d758/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:463 errors:0 dropped:0 overruns:0 frame:0
TX packets:66 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:44306 (43.2 KiB) TX bytes:5919 (5.7 KiB)
Interrupt:19 Base address:0x2000
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:8 errors:0 dropped:0 overruns:0 frame:0
TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:480 (480.0 b) TX bytes:480 (480.0 b)
客户端:
根据上面的信息,客户端克隆地址应该为:
git clone git@192.168.2.183:/home/data/git/gittest.git
我们在客户端的git Bash中演示
administrator@3S5W0LWUWE7GOX7 /E/azhui98/我的工作/git-test
$ git clone git@192.168.2.183:/home/data/git/gittest.git
Cloning into 'gittest'...
The authenticity of host '192.168.2.183 (192.168.2.183)' can't be established.
RSA key fingerprint is c1:6e:78:40:3c:94:26:d2:42:1a:11:d4:c4:f0:5c:4a.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.2.183' (RSA) to the list of known hosts.
git@192.168.2.183's password:
bash: git-upload-pack: command not found
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
administrator@3S5W0LWUWE7GOX7 /E/azhui98/我的工作/git-test
$
这里出现了错误,说找不到git-upload-pack。
回到服务端:
这是因为我们服务端安装的git不在/usr/bin目录下
需要将git安装目录bin下面的git-upload-pack 和git-receive-pack 文件复制到/usr/bin目录下。我本机上的git安装在/usr/local/git目录下。
[root@localhost bin]# cd /usr/local/git/bin
[root@localhost bin]# ll
total 22580
-rwxr-xr-x. 113 root root 5708560 Dec 5 17:17 git
-rwxr-xr-x. 2 root root 162421 Dec 5 17:17 git-cvsserver
-rwxr-xr-x. 1 root root 343666 Dec 5 17:17 gitk
-rwxr-xr-x. 113 root root 5708560 Dec 5 17:17 git-receive-pack
-rwxr-xr-x. 2 root root 2715384 Dec 5 17:17 git-shell
-rwxr-xr-x. 113 root root 5708560 Dec 5 17:17 git-upload-archive
-rwxr-xr-x. 2 root root 2766055 Dec 5 17:17 git-upload-pack
[root@localhost bin]# cp git-upload-pack /usr/bin
[root@localhost bin]# cp git-receive-pack /usr/bin
[root@localhost bin]# cd /usr/bin
[root@localhost bin]# pwd
/usr/bin
查看文件是否复制过来了
[root@localhost bin]# ll git*
-rwxr-xr-x. 1 root root 5708560 Feb 17 00:38 git-receive-pack
-rwxr-xr-x. 1 root root 2766055 Feb 17 00:38 git-upload-pack
文件复制完成后回到客户端:
administrator@3S5W0LWUWE7GOX7 /E/azhui98/我的工作/git-test
$ git clone git@192.168.2.183:/home/data/git/gittest.git
Cloning into 'gittest'...
git@192.168.2.183's password:
warning: You appear to have cloned an empty repository.
Checking connectivity... done.
administrator@3S5W0LWUWE7GOX7 /E/azhui98/我的工作/git-test
$
克隆成功。这样一个git服务器就部署好了。
来源:CSDN
作者:阿锥
链接:https://blog.csdn.net/m0_37840951/article/details/61192383