Linux 下搭建git 服务器

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux 下搭建git 服务器相关的知识,希望对你有一定的参考价值。

环境: 服务器 centos7.3 +git1.8.3.1
客户端 centos7.2 +git1.8.3.1
服务器配置;
1.安装git yum install git -y
2.创建git用户
    [[email protected] ~]# id git
    id: git: no such user
    [[email protected] ~]# useradd git
    [[email protected] ~]# id git
    uid=1001(git) gid=1001(git) groups=1001(git)

    为了安全起见,可以只允许git使用git命令

        sed -i ‘/^git/s#/bin/bash#/usr/bin/git-shell#g‘ /etc/passwd
3.在服务端创建git仓库
把/data/git/test.git设置为GIT仓库,并修改属主属组为git
    [[email protected] ~]# mkdir -p /data/git/test.git
    [[email protected] ~]# git init --bare /data/git/test.git #--bare参数创建目录结构
    Initialized empty Git repository in /data/git/test.git/
    [[email protected] ~]# chown -R git.git /data/git/test.git
    [[email protected] ~]# cd /data/git/test.git/
    [[email protected] test.git]# ll
    total 12
    drwxr-xr-x. 2 git git 6 Jun 28 22:57 branches
    -rw-r--r--. 1 root root 66 Jun 28 22:58 config
    -rw-r--r--. 1 git git 73 Jun 28 22:57 description
    -rw-r--r--. 1 git git 23 Jun 28 22:57 HEAD
    drwxr-xr-x. 2 git git 242 Jun 28 22:57 hooks
    drwxr-xr-x. 2 git git 21 Jun 28 22:57 info
    drwxr-xr-x. 4 git git 30 Jun 28 22:57 objects
    drwxr-xr-x. 4 git git 31 Jun 28 22:57 refs

客户端配置:
1.安装git yum install git -y
2.配置免密钥登录
    [[email protected] ~]#ssh-keygen -t rsa
    Generating public/private rsa key pair.
    Enter file in which to save the key (/root/.ssh/id_rsa):
    Enter passphrase (empty for no passphrase):
    Enter same passphrase again:
    Your identification has been saved in /root/.ssh/id_rsa.
    Your public key has been saved in /root/.ssh/id_rsa.pub.
    The key fingerprint is:
    ac:be:d1:12:37:89:1b:ca:52:8b:4c:b7:97:38:18:41 [email protected]
    The key‘s randomart image is:
    +--[ RSA 2048]----+
    |   E                      |
    |  .                        |
    |   .                       |
    |    .    o .              |
    |   o o + S            |
    |   o B = O .         |
    |     = B B .          |
    |       . + o            |
    |         o.              |
    +--------------------+
    [[email protected] ~]# ssh-copy-id 192.168.138.133
    /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
    /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
    [email protected]‘s password:

    Number of key(s) added: 1

    Now try logging into the machine, with: "ssh ‘192.168.138.133‘"
    and check to make sure that only the key(s) you wanted were added.
3.创建本地仓库
    [[email protected] ~]# mkdir /git
    [[email protected] ~]# cd /git/
    [[email protected] git]# ll
    total 0
    [[email protected] git]# git clone 192.168.138.133:/data/git/test.git/
    Cloning into ‘test‘...
    warning: You appear to have cloned an empty repository.
    [[email protected] git]# ll
    total 0
    drwxr-xr-x. 3 root root 17 Jul 3 20:42 test








































































以上是关于Linux 下搭建git 服务器的主要内容,如果未能解决你的问题,请参考以下文章

在 Linux 下搭建 Git 服务器

在 Linux 下搭建 Git 服务器

在 Linux 下搭建 Git 服务器

linux下搭建git服务器

linux下搭建git服务器

linux下git远程仓库的搭建