在LINUX上创建GIT服务器【转】
转自:http://blog.csdn.net/xiongmc/article/details/9176785
如果使用git的人数较少,可以使用下面的步骤快速部署一个git服务器环境。
1. Client生成 SSH 公钥,以便Server端识别。
每个需要使用git服务器的工程师,自己需要生成一个ssh公钥
进入自己的~/.ssh目录,看有没有用 文件名 和 文件名.pub 来命名的一对文件,这个 文件名 通常是 id_dsa 或者 id_rsa。 .pub 文件是公钥,另一个文件是密钥。假如没有这些文件(或者干脆连 .ssh 目录都没有),你可以用 ssh-keygen 的程序来建立它们,该程序在 Linux/Mac 系统由 SSH 包提供, 在 Windows 上则包含在 MSysGit 包里:
1 |
$ ssh-keygen |
它先要求你确认保存公钥的位置(.ssh/id_rsa),然后它会让你重复一个密码两次,如果不想在使用公钥的时候输入密码,可以留空。
现在,所有做过这一步的用户都得把它们的公钥给你或者 Git 服务器的管理者(假设 SSH 服务被设定为使用公钥机制)。他们只需要复制 .pub 文件的内容然后 e-email 之。公钥的样子大致如下:
1 |
$ cat ~/.ssh/id_rsa.pub |
2. 架设Server
首先,创建一个 ‘git’ 用户并为其创建一个 .ssh 目录,在用户主目录下:
1 |
$ sudo adduser git |
注意:将git用户添加到sudo组,以便解决
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults env_reset
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
# Host alias specification
# User alias specification
# Cmnd alias specification
# User privilege specification
root ALL=(ALL:ALL) ALL
# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL
# Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) ALL
git ALL=(ALL:ALL) ALL
# See sudoers(5) for more information on "#include" directives:
#includedir /etc/sudoers.d
接下来,把开发者的 SSH 公钥添加到这个用户的 authorized_keys 文件中。假设你通过 e-mail 收到了几个公钥并存到了临时文件里(
或git@xiongmc-desktop:~$ sudo cat /home/client2/.ssh/id_rsa.pub >> /home/git/.ssh/authorized_keys)。只要把它们加入 authorized_keys 文件
1 |
$ cat /tmp/id_rsa.john.pub >> ~/.ssh/authorized_keys |
现在可以使用 –bare 选项运行 git init 来设定一个空仓库,这会初始化一个不包含工作目录的仓库。
1 |
$ cd /opt/git |
这时,开发人员就可以把它加为远程仓库,推送一个分支,从而把第一个版本的工程上传到仓库里了。值得注意的是,每次添加一个新项目都需要通过 shell 登入主机并创建一个纯仓库。我们不妨以 gitserver 作为 git 用户和仓库所在的主机名。如果你在网络内部运行该主机,并且在 DNS 中设定 gitserver 指向该主机,那么以下这些命令都是可用的:
1 |
# 在一个工程师的电脑上 |
这样,其他人的克隆和推送也一样变得很简单:
1 |
$ git clone git@gitserver:/opt/git/project.git |
用这个方法可以很快捷的为少数几个开发者架设一个可读写的 Git 服务。
作为一个额外的防范措施,你可以用 Git 自带的 git-shell 简单工具来把 git 用户的活动限制在仅与 Git 相关。把它设为 git 用户登入的 shell,那么该用户就不能拥有主机正常的 shell 访问权。为了实现这一点,需要指明用户的登入shell 是 git-shell ,而不是 bash 或者 csh。你可能得编辑 /etc/passwd 文件
1 |
$ sudo vim /etc/passwd |
在文件末尾,你应该能找到类似这样的行:
1 |
git:x:1000:1000::/home/git:/bin/sh |
把 bin/sh 改为 /usr/bin/git-shell (或者用 which git-shell 查看它的位置)。该行修改后的样子如下:
1 |
git:x:1000:1000::/home/git:/usr/bin/git-shell |
现在 git 用户只能用 SSH 连接来推送和获取 Git 仓库,而不能直接使用主机 shell。尝试登录的话,你会看到下面这样的拒绝信息:
1 |
$ ssh git@gitserver |
Q&A参考
(4)为了集成到SCM,我们在Linxu上安装GIT
http://www.examw.com/linux/all/182529/index-2.html
在LINUX上创建GIT服务器
http://lionest.iteye.com/blog/1447310
http://blog.csdn.net/andy_android/article/details/6996134
Receiving objects: 26% (5668/21560), 8.06 MiB | 183 KiB/s 21560)
(5)
Q:
xiongmc@xiongmc-desktop:~/myproject.git$ git push origin master ssh: connect to host xiongmc-desktop port 22: Connection refused
fatal: The remote end hung up unexpectedly
xiongmc@xiongmc-desktop:~/myproject.git$ git push origin master
ssh: connect to host xiongmc-desktop port 22: Connection refused
fatal: The remote end hung up unexpectedly
A:
http://blog.csdn.net/zlm_250/article/details/7979221
sudo apt-get install openssh-server
sudo net start sshd
sudo ufw disable
ssh localhost
(6)
Q:
ubuntu系统下“关于'xx'用户不在 sudoers文件中,此事将被报告。”的解决方法
A:
http://blog.sina.com.cn/s/blog_bede36550101b0av.html
git ALL=(ALL:ALL) ALL
(7)
Q:
xiongmc@xiongmc-desktop:~/myproject.git$ git push origin master
git@xiongmc-desktop's password:
fatal: '/opt/git/project.git' does not appear to be a git repository
fatal: The remote end hung up unexpectedly
A:
http://www.dotkam.com/2010/08/22/gitolite-does-not-appear-to-be-a-git-repository/
2013-5-26
(1)
Q:
xiongmc@xiongmc-desktop:~/myproject2$ git push origin master
Agent admitted failure to sign using the key.
git@localhost's password:
error: src refspec master does not match any.
error: failed to push some refs to 'git@localhost:/opt/git/project.git/'
A:
http://www.linuxidc.com/Linux/2013-03/81022.htm
如果初始的代码仓库为空,git push origin master提交代码的时候会出现以下异常:
(2)
Q:
xiongmc@xiongmc-desktop:~/myproject2$ git push origin master
Agent admitted failure to sign using the key.
git@localhost's password:
Permission denied, please try again.
git@localhost's password:
Counting objects: 3, done.
Writing objects: 100% (3/3), 213 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
error: insufficient permission for adding an object to repository database ./objects
fatal: failed to write object
error: unpack failed: unpack-objects abnormal exit
To git@localhost:/opt/git/project.git/
! [remote rejected] master -> master (n/a (unpacker error))
error: failed to push some refs to 'git@localhost:/opt/git/project.git/'
A:
服务器无权限。
http://linsheng1990526.blog.163.com/blog/static/203824150201231423917228/
(3)
http://www.linuxidc.com/Linux/2013-03/81022.htm
Q:
xiongmc@xiongmc-desktop:~/myproject2$ git push origin master
Agent admitted failure to sign using the key.
git@localhost's password:
Counting objects: 3, done.
Writing objects: 100% (3/3), 213 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: error: is denied, because it will make the index and work tree inconsistent
remote: error: with what you pushed, and will require 'git reset --hard' to match
remote: error: the work tree to HEAD.
remote: error:
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
remote: error: its current branch; however, this is not recommended unless you
remote: error: arranged to update its work tree to match what you pushed in some
remote: error: other way.
remote: error:
remote: error: To squelch this message and still keep the default behaviour, set
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To git@localhost:/opt/git/project.git/
! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'git@localhost:/opt/git/project.git/'
A:
$cd .git
$vim config
该配置文件的原始内容为:
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
在该配置文件中加入以下内容:
[receive]
denyCurrentBranch = ignore
(4)
Linux服务器:Ubuntu配置git服务 - 逸云沙鸥
http://www.xue5.com/Server/Linux/667461.html
在LINUX上创建GIT服务器【转】的更多相关文章
- 在LINUX上创建GIT服务器
转载 如果使用git的人数较少,可以使用下面的步骤快速部署一个git服务器环境. 1. 生成 SSH 公钥 每个需要使用git服务器的工程师,自己需要生成一个ssh公钥进入自己的~/.ssh目录,看有 ...
- linux上创建ftp服务器下载文件///使用AWS服务器作为代理,下载sbt相关的包
最近觉得自己下载有些jar的速度太慢了,就在aws上下好了,然后转到我电脑上来,在aws上开了ftp服务器.结果就倒腾了一上午,作个记录,以便后面查看. 1.安装vsftpd yum -y insta ...
- linux上创建svn服务器(centos7.3)
1.安装svn yum -y install subversion 2.创建svn版本仓库 mkdir /var/svn/svnrepos svnadmin create /var/svn/svnre ...
- Linux Ubuntu搭建git服务器
1. 安装 openssh-server ,用于创建SSH服务. sudo apt-get install openssl-server 使用命令ps -e|grep ssh,查看ssh服务是否启动. ...
- 【转】在Linux下搭建Git服务器
在 Linux 下搭建 Git 服务器 环境: 服务器 CentOS6.6 + git(version 1.7.1)客户端 Windows10 + git(version 2.8.4.windows. ...
- CentOs上搭建git服务器
CentOs上搭建git服务器 首先安装setuptools wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0 ...
- Ubuntu上搭建Git服务器
下面我们就看看,如何在Ubuntu上搭建Git服务器.我们使用VMware虚拟机安装两台Ubantu系统,分别命名为gitServer和gitClient_01. 1.安装OpenSSH并配置SSH无 ...
- 在Linux上创建webrev(cont)[基于svn]
在前文中,基于git介绍了webrev工具.实际上,webrev工具还支持hg和svn.最近的工作中不可避免地要使用svn,故在此总结一下如何基于svn在Linux上创建webrev.顺便吐个槽,没有 ...
- 嵌入式Linux上通过boa服务器实现cgi/html的web上网【转】
转自:http://blog.csdn.net/tianmohust/article/details/6595996 版权声明:本文为博主原创文章,未经博主允许不得转载. 嵌入式Linux上通过boa ...
随机推荐
- python-面向对象(指数对象举例)
class Index(object): def __init__(self,index_name,index_code,closePrice_yesterday,closePrice_today): ...
- hdu 2426 Interesting Housing Problem 最大权匹配KM算法
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2426 For any school, it is hard to find a feasible ac ...
- sql records
DROP TABLE IF EXISTS student; CREATE TABLE student ( id INT NOT NULL AUTO_INCREMENT, student_name ) ...
- Leetcode#146 LRU Cache
原题地址 以前Leetcode的测试数据比较弱,单纯用链表做也能过,现在就不行了,大数据会超时.通常大家都是用map+双向链表做的. 我曾经尝试用C++的list容器来写,后来发现map没法保存lis ...
- MVC bundle(CSS或JS)
无论是有asp还是asp.net,还是php做网站经验的都知道当我们需要css或者js文件的时候我们需要在<head></head>标签中间导入我们需要的js或者css文件的路 ...
- html之colspan && rowspan讲解
1.colspan && rowspan均在td标签中使用 2.每个单元格大小一致的前提 <table border="1" bordercolor=&quo ...
- mysql存储过程和事件
1.会员表member和车辆表car,更新每个会员下面的车辆数量have_car字段. DELIMITER $$ USE $$ DROP PROCEDURE IF EXISTS `sp_update_ ...
- linux下命令行查看Memcached运行状态(shell)
stats查看memcached状态的基本命令,通过这个命令可以看到如下信息:STAT pid 22459 进程IDSTAT uptime 10 ...
- javascript和“主流大型语言”(c# JAVA C++等)的差异
1.javascript不支持overload,因为它的函数参数是以数组方式来实现的,没有固定的参数签名,所以无法重载. 2.javascript的基本类型只有5个:number string boo ...
- 开源搜索引擎Solr的快速搭建及集成到企业门户最佳实施方案--转载
笔者经过研究查阅solr官方相关资料经过两周的研究实现了毫秒级百万数据的搜索引擎的搭建并引入到企业门户.现将实施心得和步骤分享一下. 1. jdk1.6 安装jdk1.6到系统默认目录下X: ...