课程表

Git课程

工具箱
速查手册

Git 服务器搭建

当前位置:免费教程 » 软件/图像 » Git

上一章节中我们远程仓库使用了 Github,Github 公开的项目是免费的,但是如果你不想让其他人看到你的项目就需要收费。

这时我们就需要自己搭建一台Git服务器作为私有仓库使用。

接下来我们将以 Centos 为例搭建 Git 服务器。

1、安装Git

  1. $ yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel
  2. $ yum install git

接下来我们 创建一个git用户组和用户,用来运行git服务:

  1. $ groupadd git
  2. $ adduser git -g git

2、创建证书登录

收集所有需要登录的用户的公钥,公钥位于id_rsa.pub文件中,把我们的公钥导入到/home/git/.ssh/authorized_keys文件里,一行一个。

如果没有该文件创建它:

  1. $ cd /home/git/
  2. $ mkdir .ssh
  3. $ chmod 700 .ssh
  4. $ touch .ssh/authorized_keys
  5. $ chmod 600 .ssh/authorized_keys

3、初始化Git仓库

首先我们选定一个目录作为Git仓库,假定是/home/gitrepo/W3xue.git,在/home/gitrepo目录下输入命令:

  1. $ cd /home
  2. $ mkdir gitrepo
  3. $ chown git:git gitrepo/
  4. $ cd gitrepo
  5.  
  6. $ git init --bare W3xue.git
  7. Initialized empty Git repository in /home/gitrepo/W3xue.git/

以上命令Git创建一个空仓库,服务器上的Git仓库通常都以.git结尾。然后,把仓库所属用户改为git:

  1. $ chown -R git:git W3xue.git

4、克隆仓库

  1. $ git clone git@192.168.45.4:/home/gitrepo/W3xue.git
  2. Cloning into 'W3xue'...
  3. warning: You appear to have cloned an empty repository.
  4. Checking connectivity... done.

192.168.45.4 为 Git 所在服务器 ip ,你需要将其修改为你自己的 Git 服务 ip。

这样我们的 Git 服务器安装就完成了,接下来我们可以禁用 git 用户通过shell登录,可以通过编辑/etc/passwd文件完成。找到类似下面的一行:

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

改为:

  1. git:x:503:503::/home/git:/sbin/nologin
转载本站内容时,请务必注明来自W3xue,违者必究。
 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号