zoukankan      html  css  js  c++  java
  • 搭建本地Git服务器6步走

    1. 在服务器上安装git和ssh

    sudo apt install openssh-server openssh-client

    2. 在服务器上新建一个用户,比如就叫git,使用这个用户来进行git方面的服务。

    sudo adduser git

    创建用户后,切换到该用户: 

    su git
    以下操作都在Home目录下的git用户目录里进行! 

    3. 在服务器上新建一个目录来放置git仓库

    mkdir gitrepo
    git init --bare project.git

    4. 在服务器上新建ssh目录来存放访问成员的ssh公钥

    mkdir .ssh

    5. 在客户端上生成本机的ssh key,然后传递给服务器。

    ssh-keygen
    sudo scp id_rsa.pub git@192.168.174.147:~/z_id_rsa.pub

    6. 在服务器上把用户公钥添加到authorized_keys文件中

    cat z_id_rsa.pub >> ~/.ssh/authorized_keys

    现在就可以在客户机上操作远程仓库了!

    git clone git@192.168.174.147:~/gitrepo/project.git localProject

    注1:用户公钥复制到服务器后可以通过shell访问服务器,有时很危险,怎么禁止用户通过shell访问呢?

    将服务器上的/etc/passwd文件修改一下:

    git:x:1002:1002:,,,:/home/git:/bin/bash

    改为:

    git:x:1002:1002:,,,:/home/git:/usr/bin/git-shell

    这样用户在他的电脑上用shell来访问服务器时就会是这样:

    ssh git@192.168.174.147
    
    The programs included with the Debian GNU/Linux system are free software;
    the exact distribution terms for each program are described in the
    individual files in /usr/share/doc/*/copyright.
    
    Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
    permitted by applicable law.
    Last login: Wed Oct 28 19:20:43 2015 from 192.168.174.146
    fatal: Interactive git shell is not enabled.
    hint: ~/git-shell-commands should exist and have read and execute access.
    Connection to 192.168.174.147 closed.

     注2:上面的 git init --bare project.git 是创建了一个空仓库,是没有工作区的,只是为了共享。

    --End--

  • 相关阅读:
    《C++ 并发编程》- 第1章 你好,C++的并发世界
    30分钟,让你成为一个更好的程序员
    程序员技术练级攻略
    谈新技术学习方法-如何学习一门新技术新编程语言
    计算机科学中最重要的32个算法
    程序员学习能力提升三要素
    一位在MIT教数学的老师总结了十条经验
    学习算法之路
    十个顶级的C语言资源助你成为优秀的程序员
    Linux中LoadAverage分析
  • 原文地址:https://www.cnblogs.com/ibgo/p/4916638.html
Copyright © 2011-2022 走看看