Linux搭建Git服务器

正文

环境:
服务器 CentOS7.4 + git(version 1.8.3)
客户端 Windows10 + git(version 2.8.4.windows.1)

1、安装 Git

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

  • 服务器端:
  • [root@localhost ~]# yum install -y git

     

安装完后,查看 Git 版本

[root@localhost ~]# git --version
git version 1.8.3。1

 

 

  • 客户端:
    下载 Git for Windows,地址:https://www.git-scm.com/download/
    安装完之后,可以使用 Git Bash 作为命令行客户端。
    安装完之后,查看 Git 版本
  • $ git --version
    git version 2.8.4.windows.1

     

2、创建一个git用户组和用户

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

[root@localhost ~]# groupadd git
[root@localhost ~]# useradd git -g git
[root@localhost ~]# passwd git  #参数是用户名		
New password:	#设置密码

 

3、创建证书登录

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

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


附:客户端如何创建私钥:最后编辑/home/git/.ssh/authorized_keys,把客户端的公钥放进去,1个公钥1行。

# 创建私钥,文件位于用户主目录里找到.ssh目录,里面有id_rsa和id_rsa.pub两个文件
$ ssh-keygen -t rsa -C "youremail@example.com"


4、初始化Git仓库

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

[root@localhost ~]# cd /home
[root@localhost home]# mkdir gitrepo
[root@localhost home]# chown git:git gitrepo/
[root@localhost home]# cd gitrepo
[root@localhost gitrepo]# git init --bare runoob.git
Initialized empty Git repository in /home/gitrepo/runoob.git/

 

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

[root@localhost gitrepo]# chown -R git:git runoob.git

5、克隆仓库

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


192.168.45.4 为 Git 所在服务器 ip ,你需要将其修改为你自己的 Git 服务 ip。
这样我们的 Git 服务器安装就完成

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值