首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >搭建Git服务器(二) 原

搭建Git服务器(二) 原

作者头像
阿dai学长
发布2019-04-03 10:41:07
4510
发布2019-04-03 10:41:07
举报
文章被收录于专栏:阿dai_linux阿dai_linux

2.6 搭建git服务器

准备两台虚拟机:服务端、客户端

服务端

[root@z1 ~]# yum install -y epel-release git

创建用户,并设定shell:
[root@z1 ~]# useradd -s /usr/bin/git-shell git 
#目的是不让git用户远程登录  

切换至git家目录:
[root@z1 ~]# cd /home/git/

创建authorized_keys文件,并更改属主、数组权限,用来存放客户端机器上的公钥:  
[root@z1 git]# mkdir .ssh
[root@z1 git]# vim .ssh/authorized_keys
#将客户端的公钥放入该文件  

客户端生成密钥对的方法:  
[root@z2 ~]# ssh-keygen
公钥位置
[root@z2 ~]# cat /root/.ssh/id_rsa.pub


更改权限:
[root@z1 git]# chown -R git .ssh
[root@z1 git]# chmod 700 .ssh

在客户端测试能否登录服务器:

[root@z2 ~]# ssh git@192.168.8.136
Are you sure you want to continue connecting (yes/no)? yes

出现该提示,说明可以登录,因为git用户的shell禁止该用户登录虚拟机,所以在此输入密码后直接退出。

搭建仓库
[root@z1 git]# mkdir -p /data/gitroot
[root@z1 git]# cd /data/gitroot/

初始化:
[root@z1 gitroot]# git init --bare sample.git
初始化空的 Git 版本库于 /data/gitroot/sample.git/
#创建一个名为sample.git的非隐藏的裸仓库(无法操作的库)

[root@z1 gitroot]# ls
sample.git

设置权限:  
[root@z1 gitroot]# chown -R git.git sample.git

客户端

看第一节内容:

[root@z2 ~]# yum install -y epel-release git

客户端git搭建完成后执行如下操作:

克隆sample.git 库到本地:
[root@z2 gitroot]# git clone git@192.168.8.136:/data/gitroot/sample.git
正克隆到 'sample'...
warning: 您似乎克隆了一个空版本库。

[root@z2 gitroot]# ls
sample
[root@z2 gitroot]# cd sample/
[root@z2 sample]# ls -a
.  ..  .git
[root@z2 sample]# cd .git/
[root@z2 .git]# ls
branches  config  description  HEAD  hooks  info  objects  refs
[root@z2 .git]# cat config 
[core]
	repositoryformatversion = 0
	filemode = true
	bare = false
	logallrefupdates = true
[remote "origin"]
	url = git@192.168.8.136:/data/gitroot/sample.git
	fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
	remote = origin
	merge = refs/heads/master

[root@z2 .git]# cd /home/gitroot/sample
[root@z2 sample]# vim 1.txt

[root@z2 sample]# git add 1.txt 

[root@z2 sample]# git commit -m "test file"
[master(根提交) 3b92484] test file
 1 file changed, 3 insertions(+)
 create mode 100644 1.txt

推送:
[root@z2 sample]# git push -u origin master
分支 master 设置为跟踪来自 origin 的远程分支 master。
Everything up-to-date

搭建完成!

(adsbygoogle = window.adsbygoogle || []).push({});

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017/09/20 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 2.6 搭建git服务器
    • 服务端
      • 搭建仓库
    • 客户端
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档