美文网首页
Linux上搭建Git服务,客户端在Windows

Linux上搭建Git服务,客户端在Windows

作者: 飞狗未来 | 来源:发表于2018-11-26 12:31 被阅读0次

    环境

    服务器 CentOS Linux release 7.4.1708 (Core) + git(version 1.8.3.1)
    客户端 Windows7 + git(Git-2.9.3.2-64-bit.exe)

    ① 安装 Git

    Linux 做为Git服务器端系统,Windows 作为客户端系统,分别安装 Git

    服务器端:

    #yum install -y git
    

    安装完后,查看 Git 版本

    [root@localhost ~]# git --version
    git version 1.8.3.1
    

    客户端:

    下载 Git for Windows,地址:https://git-for-windows.github.io/

    安装完之后,可以使用 Git Bash 作为命令行客户端。

    安装完之后,查看 Git 版本

    $ git --version
    git version 2.9.3.windows.2
    

    ② 服务器端创建 git 用户,用来管理 Git 服务,并为 git 用户设置密码

    [root@localhost home]# id git
    id: git:无此用户
    [root@localhost home]# useradd git
    [root@localhost home]# passwd git 
    

    ③ 服务器端创建 Git 仓库

    设置 /home/data/git/gittest.git 为 Git 仓库

    然后把 Git 仓库的 owner 修改为 git

    [root@localhost home]# mkdir -p data/git/gittest.git
    [root@localhost home]# git init --bare data/git/gittest.git
    Initialized empty Git repository in /home/data/git/gittest.git/ [root@localhost home]# cd data/git/ [root@localhost git]# chown -R git:git gittest.git/
    

    ④ 客户端 clone 远程仓库

    进入 Git Bash 命令行客户端,创建项目地址(设置在 d:/www/githome)并进入:

    Administrator@PC MINGW64 /d/www/githome
    $ cd /d/www/githome
    Administrator@PC MINGW64 /d/www/githome
    

    然后从 Linux Git 服务器上 clone 项目:

    $ git clone git@192.168.56.101:/home/data/gittest.git
    

    如果SSH用的不是默认的22端口,则需要使用以下的命令(假设SSH端口号是7700):

    $ git clone ssh://git@192.168.0.111:7700/home/data/gittest.git
    

    增加新的用户

    [root@localhost home]# id git01
    id: git01:无此用户
    [root@localhost home]# useradd git01
    [root@localhost home]# passwd git01
    

    禁用git01用户的shell登陆
    出于安全考虑,第二步创建的git01用户不允许登录shell,这可以通过编辑/etc/passwd文件完成。找到类似下面的一行:

    git01:x:1001:1001:,,,:/home/git01:/bin/bash  
    

    1最后一个冒号后改为:

    git01:x:1001:1001:,,,:/home/git01:/usr/bin/git-shell  
    

    这样,git01用户可以正常通过ssh使用git,但无法登录shell,因为我们为git01用户指定的git-shell每次一登录就自动退出。

    问题1

    问题描述:fatal: destination path 'githome' already exists and is not an empty directory.
    解决方法:换了一个空的目录,重新

    相关文章

      网友评论

          本文标题:Linux上搭建Git服务,客户端在Windows

          本文链接:https://www.haomeiwen.com/subject/pewvqqtx.html