欢迎您的访问
专注于分享最有价值的互联网技术干货

十九、Git 远程服务搭建

几个T的资料等你来白嫖
双倍快乐
资源帮找!!!

我们可能需要与别人共享代码,协作开发

这时候我们就需要一台 Git 服务器作为远程 Git 仓库

下面我们就以在 Centos7 上安装 Git 服务器为例学习如何配置远程 Git 仓库

1. 安装 Git 依赖

[root@localhost ~]# yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel

2. 安装 Git

[root@localhost ~]# yum install git

3. 创建 git 用户和用户组

创建一个 git 用户组和用户,用来运行 Git 服务

[root@localhost ~]# groupadd git
[root@localhost ~]# adduser git -g git

4. 创建 ssh 登录证书

收集所有需要登录的用户的公钥,公钥位于 ~/.ssh/id_rsa.pub 文件中

把每个开发者的公钥导入到 /home/git/.ssh/authorized_keys 文件里,一行一个

如果没有 /home/git/.ssh/authorized_keys 文件则使用下面的命令创建

[root@localhost ~]# cd /home/git/
[root@localhost git]# mkdir .ssh
[root@localhost git]# chmod 700 .ssh
[root@localhost git]# touch .ssh/authorized_keys
[root@localhost git]# chmod 600 .ssh/authorized_keys

5、初始化 Git 仓库

首先我们选定一个目录作为 Git 仓库的根目录,一般情况下我们会在 git 用户目录下创建 repo 目录作为 Git 服务的根目录

首先切换到 git 用户

[root@localhost git]# su git

[git@localhost ~]$ mkdir /home/git/repo
[git@localhost ~]$ chown /home/git/repo git:git

然后在 repo 目录下创建我们的 Git 项目目录,比如 git-demo.git

目录名最好以 .git 结尾,这样在 git clone 或者 push 的时候 URL 路径更直观

[git@localhost ~]$ cd /home/home/git/repo
[git@localhost ~]$ mkdir git-demo.git
[git@localhost ~]$ chown git:git git-demo.git
[git@localhost ~]$ cd git-demo.git

[git@localhost ~]$ git init --bare .
Initialized empty Git repository in /home/git/repo/git-demo.git/

5. 禁用 git 用户登录

编辑 /etc/passwd 文件完成,找到有 git 那行

git:x:503:503::/home/git:/bin/bash

改为:

git:x:503:503::/home/git:/sbin/nologin

6. 克隆仓库

现在我们就可以克隆这个远程仓库了,假设我们服务器的 IP 是 192.168.1.8

$ git clone git@192.168.1.8:~/repo/git-demo.git
Cloning into 'git-demo'...
warning: You appear to have cloned an empty repository.
Checking connectivity... done.

如果出现类似的 Clone into 语句,则说明我们的 远程 Git 服务配置完成了

赞(0) 打赏
版权归原创作者所有,任何形式转载请联系我们:大白菜博客 » 十九、Git 远程服务搭建

评论 抢沙发

6 + 6 =
  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏