centos7下git服务器端搭建(转)
git的安装:
yum 源仓库里的 Git 版本更新不及时,最新版本的 Git 是 1.8.3.1,但是官方最新版本已经到了 2.9.2。想要安装最新版本的的 Git,只能下载源码进行安装。
1. 查看 yum 源仓库的 Git 信息:
|
1
|
# yum info git
|

可以看出,截至目前,yum 源仓库中最新的 Git 版本才 1.8.3.1,而查看最新的 Git 发布版本,已经 2.9.2 了。
2. 依赖库安装
|
1
2
|
# yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
# yum install gcc perl-ExtUtils-MakeMaker
|
3. 卸载低版本的 Git
通过命令:git –-version 查看系统带的版本,Git 版本是: 1.8.3.1,所以先要卸载低版本的 Git,命令:
|
1
|
# yum remove git
|
4. 下载新版的 Git 源码包(我放的了 /usr/local/git 的目录下了,git是我自己mkdir的目录)
进入:/usr/local下,新建git目录: # mkdir git
# cd git
在线下载最新的源码包
|
1
|
# wget https://github.com/git/git/archive/v2.9.2.tar.gz
|
也可以离线下载,然后传到 CentOS 系统中指定的目录下。
5. 解压当前目录
|
1
|
# tar -xzvf v2.9.2.tar.gz
|
6. 安装 Git
分别执行以下命令进行编译安装,编译过程可能比较漫长,请耐心等待完成。
|
1
2
3
|
# cd git-2.9.2
# make prefix=/usr/local/git all
# make prefix=/usr/local/git install
|
7. 添加到环境变量
vim /etc/profile
#如果没有vim,则安装vim工具 yum install vim
添加这一条: export PATH="/usr/local/git/bin:$PATH"
source /etc/profile #是配置立即生效
8. 查看版本号
|
1
2
|
# git --version
git version 2.9.2
|
8. 将git设置为默认路径,不然后面克隆时会报错
[root@localhost code]$ ln -s /usr/local/git/bin/git-upload-pack /usr/bin/git-upload-pack
[root@localhost code]$ ln -s /usr/local/git/bin/git-receive-pack /usr/bin/git-receive-pack
至此,CentOS 就安装上了最新版本的 Git。
第二步,创建一个git用户组和用户,用来运行git服务:
- $ groupadd git
- $ useradd git -g git
- $ passwd git #参数是用户名
最好切换到git用户 不然后面新建的git仓库都要改权限 烦烦烦!!
$ su - git
第三步,创建证书登录:
如何生成密钥:http://blog.csdn.net/permanent_2008/article/details/73839384
备注:下边虚线内容为多余内容,只是留着存档而已。于本教程没有关系
添加证书之前,还要做这么一步:
Git服务器打开RSA认证 。在Git服务器上首先需要将/etc/ssh/sshd_config中将RSA认证打开,
即:
1.RSAAuthentication yes
2.PubkeyAuthentication yes
3.AuthorizedKeysFile .ssh/authorized_keys
这里我们可以看到公钥存放在.ssh/authorized_keys文件中。
所以我们在/home/git下创建.ssh目录,然后创建authorized_keys文件,并将刚生成的公钥导入进去。
然后再次clone的时候,或者是之后push的时候,就不需要再输入密码了:
Zhu@XXX/E/testgit/8.34 $ git clone git@192.168.8.34:/data/git/learngit.git Cloning into 'learngit'... warning: You appear to have cloned an empty repository. Checking connectivity... done.
===============================
收集所有需要登录的用户的公钥,就是他们自己的id_rsa.pub文件,把所有公钥导入到/home/git/.ssh/authorized_keys文件里,一行一个。
$ cd /home/git/
$ mkdir .ssh #新建文件夹
$ chmod 700 .ssh
$ touch .ssh/authorized_keys #新建文件
$ chmod 600 .ssh/authorized_keys
第四步,初始化Git仓库
- $ cd /home/git
- $ git init --bare test.git
- Initialized empty Git repository in /home/git/test.git/
以上命令会创建一个空仓库,服务器上的Git仓库通常都以.git结尾。
第五步、本地克隆仓库
- $ git clone git@your-ip:test.git
- Cloning into 'test'...
- warning: You appear to have cloned an empty repository.
- Checking connectivity... done.
your-ip 为您 Git 所在服务器 ip
用git clone 获取服务器上的代码
[root@localhost code]$ git clone root@192.168.57.61:/root/code.git
报错如下:
bash: git-upload-pack: command not found
fatal: The remote end hung up unexpectedly
什么原因呢?原来代码服务器【192.168.57.61】上的git安装路径是/usr/local/git,不是默认路径,根据提示,在git服务器192.168.57.61上, 建立链接文件:
[root@localhost code]# ln -s /usr/local/git/bin/git-upload-pack /usr/bin/git-upload-pack
再次,执行git clone ,果真可以了。
当然,如果无法修改git代码服务器上配置,可以在clone时,添加--upload-pack选项来指定git服务器上的git-upload-pack 路径,达到上面相同的目的,如下所示:
[root@localhost code]$ git clone --upload-pack "/usr/local/git/bin/git-upload-pack" root@192.168.57.61:/root/code.git
当然,也许你会遇到git-receive-pack 之类的错误,很有可能和这个原理是一样的,请采用类似的操作即可
5.禁止Shell登录
出于安全考虑,git用户不允许登录shell,这可以通过编辑/etc/passwd文件完成。
找到类似下面的一行:
git:x:502:502::/home/git:/bin/bash
改为
git:x:502:502::/home/git:/usr/local/git/bin/git-shell
这样,git用户可以正常通过ssh使用git,但无法登录shell,因为我们为git用户指定的git-shell每次一登录就自动退出
参考文档:
git安装部署 http://www.cnblogs.com/imayanlong/p/5617626.html
git/ssh捋不清的几个问题 http://www.cnblogs.com/hustskyking/p/problems-in-git-when-ssh.html
centos7下git服务器端搭建和验证 https://my.oschina.net/u/2343829/blog/644663
Git 服务器搭建 http://www.runoob.com/git/git-server.html
Windows下SSH连接git服务器 https://www.zybuluo.com/zhutoulwz/note/30495
https://blog.csdn.net/permanent_2008/article/details/73839315
centos7下git服务器端搭建(转)的更多相关文章
- centos7下git服务器端搭建
git的安装: yum 源仓库里的 Git 版本更新不及时,最新版本的 Git 是 1.8.3.1,但是官方最新版本已经到了 2.9.2.想要安装最新版本的的 Git,只能下载源码进行安装. 1. 查 ...
- centos7下git的安装和配置
git的安装: yum 源仓库里的 Git 版本更新不及时,最新版本的 Git 是 1.8.3.1,但是官方最新版本已经到了 2.9.2.想要安装最新版本的的 Git,只能下载源码进行安装. 1. 查 ...
- Windows下Git服务器搭建[转]
Windows下Git服务器搭建 作为对前两天Git服务器搭建的一个整理,我想分别从服务端和客户端两个角度来记录下整个搭建过程,为了达到目标,我们需要哪些操作. (一)服务端软件和账号的安装配置 ...
- 【MIT6.828】centos7下使用Qemu搭建xv6运行环境
title:[MIT6.828]centos7下使用Qemu搭建xv6运行环境 date: "2020-05-05" [MIT6.828]centos7下搭建xv6运行环境 1. ...
- Ubuntu下Git从搭建到使用详解
Ubuntu下Git从搭建到使用详解 一.git的搭建 (1).sudo apt-get update (2).sudo apt-get -y install git 符:安装最新版本方法: add- ...
- Git系列(1) Windows下Git服务器搭建
作为对前两天Git服务器搭建的一个整理,我想分别从服务端和客户端两个角度来记录下整个搭建过程,为了达到目标,我们需要哪些操作. (一)服务端软件和账号的安装配置 我们这里只需要两个软件git和ssh, ...
- CentOS 6.5下Git服务器搭建
1 . Git服务器搭建 1. 环境部署 系统环境:服务器端:CentOS 6.5 ,ip:192.168.56.1 客户端:CentOS 6.5 ,ip:192.168.56.101 软件版本:服务 ...
- Centos7下git服务器及gogs部署
1.安装git # yum install -y git 2.创建git用户及组 # groupadd git # adduser git -g git # mkdir /home/git # mkd ...
- Linux centos7 下 svn 服务器搭建
摘自:https://www.cnblogs.com/mymelon/p/5483215.html 鉴于在搭建时,参考网上很多资料,网上资料在有用的同时,也坑了很多人 本文的目的,也就是想让后继之人在 ...
随机推荐
- <YaRN><Official doc><RM REST API's>
Overview ... YARN Architecture The fundamental idea of YARN is to split up the functionalities of re ...
- dos命令:网络相关命令
网络相关命令 一.Arp命令 1.介绍 显示和修改地址解析协议(ARP)使用的“IP 到物理”地址转换表. 2.语法 ARP -s inet_addr eth_addr [if_addr] ARP ...
- centos6.6安装hadoop-2.5.0(五、部署过程中的问题解决)
操作系统:centos6.6 环境:selinux disabled:iptables off:java 1.8.0_131 安装包:hadoop-2.5.0.tar.gz 一.安装过程中会出现WAR ...
- usort 函数
function getNameFromNumber($num){ // Used to figure out what the Excel column name would be for a gi ...
- kbmMW功能#5 - kbmMWProcess单元
在新的kbmMW v.5.06.20版本中新加kbmMWProcess单元.通过TkbmMWProcess类的各种类方法,可以轻松地在Windows上对外部进程进行分组,启动和停止.在即将发布的小修补 ...
- 解决MySQL不允许远程连接的问题
进入MySQL:mysql -u root -p mysql> GRANT ALL privileges ON *.* TO 'root' @'localhost' IDENTIFIED ...
- ipv6地址管理
为了彻底解决IPv4存在的问题,国际互联网工程任务组从1995年开始,着手研究开发下一代IP协议,即IPv6.可彻底解决IPv4地址不足的问题,除此之外,IPv6还采用分级地址模式.高效IP包头.主机 ...
- python day 16作业
day18天作业及默写1,完成下列功能: 1.1创建一个人类Person,再类中创建3个静态变量(静态字段) animal = '高级动物' soup = '有灵魂' language = '语言' ...
- [转][译] Closures in Lua - Lua中的闭包
http://www.cnblogs.com/plodsoft/p/5900270.html?utm_source=tuicool&utm_medium=referral 原文:(PDF) . ...
- ubuntu discuz 该函数需要 PHP 支持 XML。请联系空间商,确定开启了此项功能
apt-get install php-xml apt-get install php-xml-parser