zoukankan      html  css  js  c++  java
  • 笔记一、Git服务器【转】

    传输协议: 本地传输,SSH协议,Git协议,HTTP协议
     
    git clone /home/git/project.git                      // 本地clone
    git clone ssh://user@server:/home/git/project.git     // 使用SSH协议clone, 可读写
    git clone user@server:/home/git/project.git           // 默认使用SSH协议clone, 可读写
    git clone http://example.com/git/project.git         // 使用HTTP协议clone, 只读
     
    git clone --bare /home/myproject myproject.git       // clone为纯仓库
     
     
    帐号管理方法
    (ssh密钥方式有待研究, 群组方式可以)
     
    最常用的帐号管理方法为: 
       在主机上建立一个 git账户,
       让每个需要写权限的人发送一个SSH公钥,然后将其加入git账户的 ~/.ssh/authorized_keys文件
     
    1、服务器创建git用户
    $ sudo adduser git
    $ su git
    $ cd
    $ mkdir .ssh
     
    2、开发者生成SSH公钥
    $ su cxt
    $ cd
    $ mkdir .ssh
    $ cd ssh
    $ ssh-keygen    // 创建公钥私钥 id_rsa, id_rsa.pub
     
    3、导入公钥到git用户的ssh目录下
    $ su git
    $ cd
    $ cat /home/cxt/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
     
    4、参考服务器搭建方式
     
    5、git用户登录的防范措施
    $ sudo vim /etc/passwd
    $ git:x:1000:1000::/home/git:/bin/bash  改为
    $ git:x:1000:1000::/home/git:user/bin/git-shell   // git用户只能用SSH连接来推送和获取git仓库, git用户不能使用主机shell了
     
    $ su git
    fatal: Interactive git shell is not enabled.
    hint: ~/git-shell-commands should exist and have read and execute access.
     
    $ ssh git@192.168.3.254     // 只能通过ssh访问git用户
     
     
    6. 群组管理
       git用户所属群一般为git
    $ grep 'git' /etc/group /etc/gshadow
    /etc/group:git:x:1003:
    /etc/gshadow:git:!::
     
    将cxt用户加入git群组
    $ gpasswd -a cxt git
     
    更改/home/git下xxx.git目录群组权限
    $ sudo chmod g+w -R /home/git/xxx.git
     
    屏蔽/home/git/.ssh目录权限
    $ sudo chmod 700 -R /home/git/.ssh     // 所有人都不能看到公钥
     
     
    服务器搭建方式:
     
    git init --bare     // 服务器
     
    # 在John电脑上
    $ cd myproject
    $ git init
    $ git add .
    $ git commit -m "initial commit"
    $ git remote add origin user@server:/home/git/project.git    // 远程分支第一个版本
    $ git push origin master
     
    # 在Josie电脑上
    $ git clone user@server:/home/git/project.git
    $ vim README
    $ git commit -am "fix for the README file"          // 其他人clone与推送
    $ git push origin master
     
     
    客户端提交常见错误:
     
    1. remote: error: insufficient permission for adding an object to repository database ./objects
      服务端没有可写目录的权限
      sudo chmod -R g+w xxx.git/.objects
     
    2. $ ssh git@192.168.3.254
    fatal: Interactive git shell is not enabled.
    hint: ~/git-shell-commands should exist and have read and execute access.
    Connection to 192.168.3.254 closed.
     
    原因:
        按照提示,在git用户的主目录下面需要存在git-shell-commands目录
  • 相关阅读:
    HTB-靶机-Charon
    第一篇Active Directory疑难解答概述(1)
    Outlook Web App 客户端超时设置
    【Troubleshooting Case】Exchange Server 组件状态应用排错?
    【Troubleshooting Case】Unable to delete Exchange database?
    Exchange Server 2007的即将生命周期,您的计划是?
    "the hypervisor is not running" 故障
    Exchange 2016 体系结构
    USB PE
    10 months then free? 10个月,然后自由
  • 原文地址:https://www.cnblogs.com/sky-heaven/p/5180596.html
Copyright © 2011-2022 走看看