搭建git服务器

服务端192.168.221.20,安装git,创建用户,创建文件authorized_keys,权限,属主属组

[[email protected]-002 yum.repos.d]# yum install git -y
[[email protected]-002 yum.repos.d]# useradd -s /usr/bin/git-shell git
[[email protected]-002 yum.repos.d]# cd /home/git/
[[email protected]-002 git]# mkdir .ssh
[[email protected]-002 git]# touch .ssh/authorized_keys
[[email protected]-002 git]# chmod 600 .ssh/authorized_keys
[[email protected]-002 git]# chown -R git:git .ssh/

客户端192.168.221.10,将公钥放到服务端.ssh/authorized_keys

[[email protected] apeng]# cat /root/.ssh/id_rsa.pub 
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCZ4he1cZhRT7LHd5QXtdMqA2g0ub+tp9uau0gG6rN5cRcHZhJv4vyFhuyhFSR4dHNPzMg+j5KSfWtkhikW52NXZ/+sgYC2/aS7C+vTBZZx82fL2YiF6eDOB0VZR6yTZggWQjljne8sle1W6wQiHkshbRFeV+pg4sYTXI2LHlzFcsFuyOhF4L6Cykg/v9s8ZvotRGRMLWBHAzCj+iI0pzwCJrHMzN6yiV6JH9ZyN3IrQs2cEoy+dbV/UxztPIc5f6tns+5jGeQtkUL102c+NFQ19qmU1kU+lbZ91+/42pbndJrrdyCdpeAmMDQSqe+7/M+gOwDCKyjNZigeKfLv0tXH [email protected]

服务端保存客户端的公钥

vim .ssh/authorized_keys  //放入客户端的公钥

客户端连接服务端

[[email protected] apeng]# ssh [email protected]
The authenticity of host '192.168.221.20 (192.168.221.20)' can't be established.
ECDSA key fingerprint is SHA256:UiIDDUfExrEZLxrI8+z6PWjWsNCO2GTDDfTKpEhQaWY.
ECDSA key fingerprint is MD5:4e:79:bd:c6:bb:8d:b7:ee:1a:a4:cb:25:03:22:10:5f.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.221.20' (ECDSA) to the list of known hosts.
fatal: Interactive git shell is not enabled.
hint: ~/git-shell-commands should exist and have read and execute access.
Connection to 192.168.221.20 closed.

服务端建立裸仓库,修改仓库的属主,属组

[[email protected]-002 git]# mkdir -p /data/gitroot
[[email protected]-002 git]# cd /data/gitroot
[[email protected]-002 gitroot]# git init --bare sample.git
初始化空的 Git 版本库于 /data/gitroot/sample.git/
[[email protected]-002 gitroot]# ls
sample.git
[[email protected]-002 gitroot]# chown -R git:git sample.git/

客户端克隆远程的仓库,建立一些文件推送到服务端

[[email protected] ~]# mkdir /copy
[[email protected] ~]# cd /copy
[[email protected] copy]# git clone [email protected]:/data/gitroot/sample.git
[[email protected] copy]# cd sample/
[[email protected] sample]# echo "client" > client.txt
[[email protected] sample]# git add client.txt
[[email protected] sample]# git commit -m "add client.txt"
[master(根提交) 61a074d] add client.txt
 1 file changed, 1 insertion(+)
 create mode 100644 client.txt
 [[email protected] sample]# git push

git 搭建

[[email protected] sample]# git push origin master 
Counting objects: 3, done.
Writing objects: 100% (3/3), 217 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To [email protected]192.168.221.20:/data/gitroot/sample.git
 * [new branch]      master -> master

在客户端上再次建立一些文件,看看情况

[[email protected] sample]# echo "client1" > client1.txt
[[email protected] sample]# git add client1.txt
[[email protected] sample]# git commit -m "add client1.txt"
[[email protected] sample]# git push

在客户端上将服务端上的新的变更克隆到另外一个目录下

[[email protected] sample]# mkdir /update
[[email protected] sample]# cd /update
[[email protected] update]# git clone [email protected]:/data/gitroot/sample.git
[[email protected] update]# ls sample/
client1.txt  client.txt

修改/copy/sample/client1.txt文件,推送到服务端,到/update/sample获取更新的数据
git 搭建

[[email protected] sample]# git add client1.txt
[[email protected] sample]# git commit -m "modify client1.txt"
[master a89467d] modify client1.txt
 1 file changed, 1 insertion(+)
[[email protected] sample]# git push