在CentOS搭建Git服务器 转
在CentOS搭建Git服务器
前言
我们可以GitHub发布一些开源代码的公共仓库,但对于私密仓库就需要收费了。公司内部通常会搭建自己的Git服务器,我也通过在自己的服务器上搭建练习一下。
开始前先说一下服务器信息,这里是阿里云的CentOS 6.5 64位操作系统。
一 确认服务器是否安装Git
[root@iZ25r8k6ifuZ git]# rpm -qa git
git-1.7.1-3.el6_4.1.x86_64
这里也已经安装过了,如果没有安装可以用yum install git 安装。
二 创建git用户
这里你可以选择新建一个用户来测试,也可以直接使用你的root进行以下操作。笔者也是看着资料一步一步来的,这里创建一个新用户teslachen进行操作。[root@iZ25r8k6ifuZ ~]# useradd tesla
[root@iZ25r8k6ifuZ ~]# passwd tesla
更改用户 tesla 的密码 。
新的 密码:
无效的密码: 它没有包含足够的不同字符
无效的密码: 过于简单
重新输入新的 密码:
passwd: 所有的身份验证令牌已经成功更新。
注1:创建用户权限不够请加上sudo;
注2:设置用户密码太过简单的话会有提示,但依旧可以设置成功。
三 生成ssh公钥
许多 Git 服务器都使用 SSH 公钥进行认证。 为了向 Git 服务器提供 SSH 公钥,如果某系统用户尚未拥有密钥,必须事先为其生成一份。
linux 可以在本机运行ssh-keygen -t rsa生成密钥,把.pub文件拷到服务器上。[root@iZ25r8k6ifuZ ~]# su tesla
[tesla@iZ25r8k6ifuZ root]$ cd ~
[tesla@iZ25r8k6ifuZ ~]$ mkdir .ssh
[tesla@iZ25r8k6ifuZ ~]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/tesla/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/tesla/.ssh/id_rsa.
Your public key has been saved in /home/tesla/.ssh/id_rsa.pub.
The key fingerprint is:
13:bf:75:ba:67:7f:0e:a0:47:7a:fe:25:bc:81:85:c3 tesla@iZ25r8k6ifuZ
The key's randomart image is:
+--[ RSA 2048]----+
| |
| |
| . |
| o . . |
| S . E o |
| . O |
| + = = .|
| + .o.|
| o+oo+|
+-----------------+
[tesla@iZ25r8k6ifuZ ~]$ cd .ssh/
[tesla@iZ25r8k6ifuZ .ssh]$ cat id_rsa.pub >> ~/.ssh/authorized_keys
exit
四 添加tesla到sudoers文件
tesla用户现在对一些文件夹没有操作权限,修改/etc/sudoers文件来改变他的权限。最高管理员用户用下面命令打开。[root@iZ25r8k6ifuZ ~]# visudo
然后我们在vim中找到下面这行
root ALL=(ALL) ALL
按i键开始插入,回车一下在下面一行加上
tesla ALL=(ALL) ALL
接着按下esc键,输入 :wq ,回车保存退出
五 创建Git代码仓库
[root@iZ25r8k6ifuZ ~]# mkdir /teslaRepo
[root@iZ25r8k6ifuZ ~]# cd /teslaRepo/
[root@iZ25r8k6ifuZ teslaRepo]# sudo mkdir teslaProject.git
[root@iZ25r8k6ifuZ teslaRepo]# chown tesla:tesla /teslaRepo/
[root@iZ25r8k6ifuZ teslaRepo]# chown -R tesla:git /teslaRepo/
[root@iZ25r8k6ifuZ teslaRepo]# cd teslaProject.git/
[root@iZ25r8k6ifuZ teslaProject.git]# sudo git --bare init
Initialized empty Git repository in /teslaRepo/teslaProject.git/
这样一个叫teslaProject得Git仓库就创建好了
六 本地测试使用
你可以直接在服务器上进行本地测试,也可以直接用你的电脑来测试。下面我是使用自己的MBP来进行的测试。localhost:~ okay$ cd Desktop/git/
localhost:git okay$ mkdir teslaRepo
localhost:git okay$ cd teslaRepo/
localhost:teslaRepo okay$ git init
Initialized empty Git repository in /Users/okay/Desktop/git/teslaRepo/.git/
localhost:teslaRepo okay$ git remote add origin tesla@123.57.159.74:/teslaRepo/teslaProject.git
上面的命令在本地创建了一个文件夹并添加了服务器上的远程仓库localhost:teslaRepo okay$ touch a.txt
localhost:teslaRepo okay$ git add a.txt
localhost:teslaRepo okay$ git commit -m "init commit"
[master (root-commit) d14cd3b] init commit
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 a.txt
上面的命令在本地创建了一个a.txt并在本地提交了一次localhost:teslaRepo okay$ git push origin master
tesla@123.57.159.74's password:
Counting objects: 3, done.
Writing objects: 100% (3/3), 202 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To tesla@123.57.159.74:/teslaRepo/teslaProject.git
* [new branch] master -> master
上面的命令将本地代码push到远程服务器上去了,下面我们在本地clone一次看下是否正确
七 本地clone
localhost:git okay$ mkdir ttt
localhost:git okay$ cd ttt
localhost:ttt okay$ git clone tesla@123.57.159.74:/teslaRepo/teslaProject.git
Cloning into 'teslaProject'...
tesla@123.57.159.74's password:
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.
Checking connectivity... done.
clone完成,让我们看一下文件夹目录

之前push到服务器上的a.txt文件已经被clone下来
在CentOS搭建Git服务器 转的更多相关文章
- CentOS搭建Git服务器及权限管理
声明:本教程,仅作为配置的记录,细节不展开,需要您有一点linux的命令基础,仅作为配置参考. 1. 系统环境 系统: Linux:CentOS 7.2 64位 由于CentOS已经内置了OpenSS ...
- 在centos搭建git服务器时,不小心把/home/git目录删除了,我是怎么恢复的
在centos搭建git服务器时,不小心把/home/git目录删除了,我是怎么恢复的 在删除掉/home/git目录后,每次 git push提交时,都让填写密码,烦 第一步:在本地找到id_rsa ...
- centos 搭建git服务器
centos 6搭建git服务器 安装 rpm -ivh http://mirrors.aliyun.com/epel/epel-release-latest-6.noarch.rpm yum ins ...
- 自定义Git之使用centos搭建git 服务器
Github 公开的项目是免费的,但是如果你不想让其他人看到你的项目就需要收费. 这时我们就需要自己搭建一台Git服务器作为私有仓库使用. 接下来我们将以 Centos 为例搭建 Git 服务器. 1 ...
- Centos搭建 Git 服务器教程
搭建 GIT 服务器教程 下载安装 git Git 是一款免费.开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目. 此实验以 CentOS 7.2 x64 的系统为环境,搭建 git 服 ...
- CentOS 搭建 Git 服务器
官方文档移步 Git 服务器的搭建 安装 Git #yum install git 创建 Git 专用用户 #useradd git,改密码 #passwd git,切换至 Git 用户 #su gi ...
- CentOS搭建git服务器实测
Git 可以使用四种主要的协议来传输数据:本地传输,SSH 协议,Git 协议和 HTTP 协议 1,安装: CentOS/Fedora: yum install git Ubuntu/Debian: ...
- CentOS搭建GIT服务器
安装git # 请确保您切换到了root账户 $ su root $ yum install -y git # 验证是否安装成功 $ git --version # 输出如下内容表示成功: git v ...
- centos搭建git服务器(转)
一:git服务安装 1.安装git相关组件 [root@gitserver ~] yum -y install git 2.创建git用户 [root@gitserver ~] groupadd gi ...
随机推荐
- ios 网络字节顺序的转换HTOS
最近用socket发送data遇到个问题,字节高地位和服务器不匹配,搞了好久才找到解决的方案,主要用到两个函数HTOL HTOS STOH LTOL 故写此博文 什么是字节序 采用维基百科的解释如下: ...
- IT全称
1.jar,war,ear(摘自:http://blog.sina.com.cn/s/blog_54bb7b950100wnbb.html) Jar文件(扩展名为. Jar)包含Java类的普通库.资 ...
- qt 5 小练习 简易画板
如何在窗口上画线?用一根根线来拼凑图案呢? 想必大家都知道点的集合是线,而线的集合就是很多线啦,用线的集合我们能拼凑出许许多多的图案.于是我就要记录自己跟着老师的学习之路啦: 既然有集合的话,势必要用 ...
- 由tomcat启动想到的
1.batch:批处理文件,表示一批 2.profile:轮廓 3.用户变量和系统变量的关系是什么? 答:点击"我的电脑→属性→高级"标签的"环境变量&quo ...
- csu 10月 月赛 F 题 ZZY and his little friends
一道字典树异或的题,但是数据比较水,被大家用暴力给干掉了! 以前写过一个类似的题,叫做the longest xor in tree: 两个差不多吧! 好久没写字典树了,复习一下! 代码: #incl ...
- POJ 2750 Potted Flower(线段树的区间合并)
点我看题目链接 题意 : 很多花盆组成的圆圈,每个花盆都有一个值,给你两个数a,b代表a位置原来的数换成b,然后让你从圈里找出连续的各花盆之和,要求最大的. 思路 :这个题比较那啥,差不多可以用DP的 ...
- TIPSO--基于JQUERY的消息提示框插件,用起来蛮顺手
项目产品经理要求, 呵呵,关于描述,十个字以内的,直接显示,多于十个字的,用消息框提示: 相关模板及JS如下: $(function() { $('.tip').tipso({ useTitle: f ...
- 第一回写的用arraylist模拟栈操作
package hashMap; import java.util.ArrayList; import d.Student; /** * 用ArrayList模拟栈操作 * @author zhuji ...
- [笔记] 走进 Pocket,看看只有 20 位员工的 Pocket 是如何搞定 2000 万用户的
走进 Pocket,看看只有 20 位员工的 Pocket 是如何搞定 2000 万用户的 保持专注. 不断更新优先级. 对产品有主人翁意识. (觉得做好产品是自己的职责, 不是应付工作) 你的用户如 ...
- 【HDOJ】4183 Pahom on Water
就是一个网络流.red结点容量为2,查看最大流量是否大于等于2.对于条件2,把边反向加入建图.条件1,边正向加入建图. /* 4183 */ #include <iostream> #in ...