准备工作:

1、一台虚拟linux环境和window

开始工作

1、安装git(略)

  2、创建git用户和创建test.git裸仓库

[root@localhost ~]# useradd -m git #创建用户,shell是bash
[root@localhost ~]# su git
[git@localhost root]$  cd ~
[git@localhost ~]$ mkdir repository && cd repository
[git@localhost repository]$  git init --bare test.git

  此时在repository目录生成test.git,作为远程仓库

  3、生成公私钥(多种工具生成),此处使用ssh-keygen,大概情形如下

[git@localhost .ssh] cd /home/git/.ssh  #没有.ssh目录,自行创建
[git@localhost .ssh]$ ssh-keygen -t rsa -C 'git@master.com'
Generating public/private rsa key pair.
Enter file in which to save the key (/home/git/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/git/.ssh/id_rsa.
Your public key has been saved in /home/git/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:J06qIJSTy2n0kSfmAwavvxrv2fwK1pd2UwifUg6axl4 git@master.com
The key's randomart image is:
+---[RSA 2048]----+
|                 |
|                 |
|.     o .        |
|..o..o * o       |
| O.==.E S o      |
|=.O++. * +       |
|+=++o = +        |
|.* *.+ . .       |
|.o*.=o.          |
+----[SHA256]-----+

  会生成两个文件id_rsa和id_rsa.pub,以.pub结尾的是公钥,将公钥放到authorized_keys文件中,实现免密登录

[git@localhost .ssh]$ cat id_rsa.pub >> ./authorized_keys

  4、window客户端

$ git clone git@ip:/home/git/repository/test.git

  5、Linux客户端

[git@localhost ~]$ mkdir test && cd test
[git@localhost test]$ git init #初始化仓库
[git@localhost test]$ git remote add origin git@ip:/home/git/repostroy/test.git
[git@localhost test]$ git pull origin master
The authenticity of host 'ip (ip)' can't be established.
ECDSA key fingerprint is SHA256:uSKcAOh8Q8Lca9vlPQhjVGm8lPtEpc09Ze4GTW70lFs.
ECDSA key fingerprint is MD5:66:f8:99:85:bc:e2:20:51:f0:4e:59:88:30:2e:5a:2d.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'ip' (ECDSA) to the list of known hosts.
remote: Counting objects: 100, done.
remote: Compressing objects: 100% (73/73), done.
remote: Total 100 (delta 5), reused 0 (delta 0)
Receiving objects: 100% (100/100), 7.68 KiB | 0 bytes/s, done.
Resolving deltas: 100% (5/5), done.
From 192.168.0.159:/home/git/repostroy/test
 * branch            master     -> FETCH_HEAD

  6、使用post-update实现自动化

[git@localhost ~]$ /home/git/repostroy/test.git/hooks/post-update
# 添加如下内容
unset GIT_DIR
cd /home/git/fail
git pull origin master

  7、测试(window客户端)

  成功!!!!

碰到的几个问题

1、post-receive和post-update的区别、

2、远程无法执行

答、需要给post-receive或者post-update执行权限

3、如图

  

答:要在git用户生成公私钥,因为git远程库是用git用户做pull操作的

4、cannot open .git/FETCH_HEAD: Permission denied

 答:查看FETCH_HEAD的所属主、所属组是不是git,不是用户chown命令修改

5、暂时没有

  

  

最新文章

  1. [转]Android应用程序框架思路整理
  2. url中
  3. django缓存
  4. 通过hibernate session.connection()获得数据库连接时,导致的查询缓慢甚至假死机问题
  5. iOS 获得指定文件夹下的指定格式文件
  6. ibatis基础
  7. UVALive 7461 Separating Pebbles (计算几何)
  8. Cactus入门
  9. SHELL:Find Memory Usage In Linux (统计每个程序内存使用情况)
  10. Centos6.2_(64位)服务器环境配置:源码编译Nginx
  11. Win8/8.1 下映像管理和恢复环境的配置
  12. 《算法导论》学习总结 — XX.第22章 图的基本算法
  13. 动态加载js css 插件
  14. 基于Vue+node.js的个人博客
  15. 剑指Offer——栈的java实现和栈的应用举例
  16. java第二次作业之一
  17. 表单中input name属性有无[]的区别
  18. [ZJOI2012]波浪
  19. VMware安装CentOS6
  20. sublime 格式化代码

热门文章

  1. Vue之webpack的安装与配置及其简单应用
  2. Python--day41--thread1.join()
  3. SVN常用命令之checkout
  4. Laravel报错Call to undefined function Illuminate\Encryption\openssl_cipher_iv_length()
  5. Linux 内核PC/104 和 PC/104+
  6. webpack+babel+react+antd技术栈的基础配置
  7. 前端js页面跳转
  8. 2019-10-12-win10-uwp-非ui线程访问-ui-
  9. Linux网络IO模型
  10. 【Docker】镜像基本操作