zoukankan      html  css  js  c++  java
  • 在MacOS上搭建Git 服务器

    创建Git服务器账号

     
    打开【系统设置】中的【用户和组】,加入新用户【git】,该用户主要是提供git服务器的安全和配置环境
    图1 加入新用户
     
    配置Git服务器环境
     
    1. 在Terminal中登陆该用户命令如下:
         ssh -l git 127.0.0.1
         或使用
         su git
     
    2. 配置Git服务器路径
         现在可以用 —shared,--bare 选项运行 git init 来建立一个裸仓库,这会初始化一个不包含工作目录的仓库。
         bogon:octopus.git git$ git init —bare --shared
         Initialized empty shared Git repository in /Users/git/git.repository/octopus.git/
         bogon:octopus.git git$ ls
         HEAD          config          hooks          objects
         branches     description     info          refs
     
    3. 配置访问权限
         当前笔者默认使用ssh协议(该协议比较简单并且同时支持读写),对于客户端来说,它需要有公钥才能访问ssh服务器,为此需要为【git】用户建立【.ssh】公钥文件夹。
         bogon:// git$ cd ~/.ssh
         bogon:.ssh git$ ls
         authorized_keys
         
         【authorized_keys】该文件用来给用户授权。稍后,咱们在配置用户访问时,会使用该文件。
    4. 测试Git服务器
         退出该用户终端,使用当前【kuoxin】用户访问Git服务器,命令如下:
         bogon:temp kuoxin$ git clone ssh://git@127.0.0.1/Users/git/git.repository/octopus.git
         Cloning into 'octopus'...
         The authenticity of host '127.0.0.1 (127.0.0.1)' can't be established.
         RSA key fingerprint is 9e:d6:3e:4f:e5:ec:02:73:8c:3c:58:9b:d6:9b:ab:fc.
         Are you sure you want to continue connecting (yes/no)? yes
         Warning: Permanently added '127.0.0.1' (RSA) to the list of known hosts.
         Password:
         warning: You appear to have cloned an empty repository.
         Checking connectivity... done.
     
    配置客户单环境
         
    1. 创建客户端公钥
         当Git服务器使用ssh协议访问时,如果读写Git服务器的话,就要求有ssh安全访问,因此需要建立该用户的公钥,放入到git服务器(当前为同Mac上的不同账户模拟环境)的【.ssh】目录下,以便服务器上的ssh值守程序可以验证用户读写访问。
     
         bogon:.ssh kuoxin$ ssh-keygen
         Generating public/private rsa key pair.
         Enter file in which to save the key (/Users/kuoxin/.ssh/id_rsa): kuoxin_rsa
         Enter passphrase (empty for no passphrase):
         Enter same passphrase again:
         Your identification has been saved in kuoxin_rsa.
         Your public key has been saved in kuoxin_rsa.pub.
         The key fingerprint is:
         36:10:55:aa:9b:5b:0a:0c:b6:71:0f:ac:a7:a2:5e:97 kuoxin@bogon
         The key's randomart image is:
         +--[ RSA 2048]----+
         |      .....      |
         |       . .       |
         |      . .        |
         |   .   o        |
         |  + + . S     |
         | . B o.+ .    |
         |  o.+E+ .    |
         |. .o.. +       |
         |+o.   o        |
         +-----------------+
     
        bogon:.ssh kuoxin$ ls
        github_rsa     github_rsa.pub     known_hosts     kuoxin_rsa     kuoxin_rsa.pub
     
    2. 配置客户端账号访问
         需要将新生成的kuoxin_rsa.pub文件,拷贝到git服务器上的git账号下的【.ssh】目录,并且将开发者的 SSH 公钥添加到的 authorized_keys 文件中。操作如下:
         
         列出当前【kuoxin】开发者账号下的【.ssh】路径下生成的公钥文件
         bogon:.ssh kuoxin$ ls     
         github_rsa     github_rsa.pub     known_hosts     kuoxin_rsa     kuoxin_rsa.pub
         
         由于本人使用是同机的不同账户,需要拷贝公钥到/tmp路径下
         bogon:.ssh kuoxin$ cp kuoxin_rsa.pub /tmp/
     
         把公钥加入到【git】用户的【.ssh】目录下的authorized_keys文件中,如果希望多个开发者使用该版本库,只需要要把它们逐个追加到 authorized_keys 文件尾部即可,当前就只加入kuoxin用户公钥。
         bogon:.ssh git$ cat /tmp/kuoxin_rsa.pub >> authorized_keys     
     
    3.加入源代码工程到Git服务器
     
         bogon:git.repo kuoxin$ cd octopus 
      bogon:octopus kuoxin$ git init 
      bogon:octopus kuoxin$ git add . 
      bogon:octopus kuoxin$ git commit -m 'initial commit’ 
      bogon:octopus kuoxin$ git remote add origin ssh://git@127.0.0.1/Users/git/git.repository/octopus.git
      bogon:octopus kuoxin$ git push origin master
     
    4.  测试工程
         我们使用sourceTree 来测试。
         
         图2 配置远程Git服务器
     
    图3 导出源程序
     
     
    后话
     
         1. 以上方式主要是适合小规模团队或者个人使用,对于大团队来说,还是请公司的IT来搞定比较好。
         2. Git服务器支持多种协议,如http/https, git, local, ssh
         3. Git主要是配置用户管理比较复杂,可以使用gitosis。
     
  • 相关阅读:
    最详细的Vue Hello World应用开发步骤
    SAP Fiori + Vue = ?
    golang--连接redis数据库并进行增删查改
    golang--redis基本介绍
    golang--海量用户即时通讯系统
    (四十六)golang--网络编程(简易的聊天系统)
    动态规划--矿工挖矿
    (四十五)golang--反射
    动态规划--爬楼梯问题(入门)
    (四十四)golang--协程(goroutine)和管道(channel)相结合实例
  • 原文地址:https://www.cnblogs.com/kuoxin/p/4577323.html
Copyright © 2011-2022 走看看