
假设你已经有sudo权限的用户账号,下面,正式开始安装。
第一步,安装git:
$ sudo apt-get install git
第二步,创建一个git用户,用来运行git服务:
$ sudo adduser git
第三步,创建证书登录:
收集所有需要登录的用户的公钥,就是他们自己的id_rsapub文件,把所有公钥导入到/home/git/ssh/authorized_keys文件里,一行一个。
第四步,初始化Git仓库:
先选定一个目录作为Git仓库,假定是/srv/samplegit,在/srv目录下输入命令:
$ sudo git init --bare samplegit
Git就会创建一个裸仓库,裸仓库没有工作区,因为服务器上的Git仓库纯粹是为了共享,所以不让用户直接登录到服务器上去改工作区,并且服务器上的Git仓库通常都以git结尾。然后,把owner改为git:
$ sudo chown -R git:git samplegit
第五步,禁用shell登录:
出于安全考虑,第二步创建的git用户不允许登录shell,这可以通过编辑/etc/passwd文件完成。找到类似下面的一行:
git:x:1001:1001:,,,:/home/git:/bin/bash
改为:
git:x:1001:1001:,,,:/home/git:/usr/bin/git-shell
这样,git用户可以正常通过ssh使用git,但无法登录shell,因为我们为git用户指定的git-shell每次一登录就自动退出。
第六步,克隆远程仓库:
现在,可以通过git clone命令克隆远程仓库了,在各自的电脑上运行:
$ git clone git@server:/srv/samplegit
Cloning into 'sample'
warning: You appear to have cloned an empty repository
剩下的推送就简单了。首先我们分别在Git服务器和客户机中安装Git服务程序(刚刚实验安装过就不用安装了):
[root@linuxprobe ~]# yum install git
Loaded plugins: langpacks, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management You can use subscription-manager to register
Package git-1831-4el7x86_64 already installed and latest version
Nothing to do
然后创建Git版本仓库,一般规范的方式要以git为后缀:
[root@linuxprobe ~]# mkdir linuxprobegit
修改Git版本仓库的所有者与所有组:
[root@linuxprobe ~]# chown -Rf git:git linuxprobegit/
初始化Git版本仓库:
[root@linuxprobe ~]# cd linuxprobegit/
[root@linuxprobe linuxprobegit]# git --bare init
Initialized empty Git repository in /root/linuxprobegit/
其实此时你的Git服务器就已经部署好了,但用户还不能向你推送数据,也不能克隆你的Git版本仓库,因为我们要在服务器上开放至少一种支持Git的协议,比如>为有读写权限的用户建立一个分组。根据你的 *** 作系统,你可以用groupadd命令来实现,用vigr来编辑分组文件,或者直接编辑/etc/group文件。在最后,你会在/etc/group文件中看到如下一行
1
repogroup::10005:marry,john,violet
其中,repogroup是准许接入这个仓库的组的名字。10005是一个独一无二的分组识别数字,marry,john,violet则是获准接入这个仓库的用户。
决定Git仓库的路径。它既可以放在你的home路径下(eg /home/yourname/gitroot),也可以放在一个专用的路径下(eg /var/gitroot)
配置权限,让Git用户可以访问这个目录
1
2
chmod g+rx /path-to/gitroot
chown :grouprepo /path-to/gitroot
建立新的Git仓库,叫做newrepo
1
2
cd /path-to/gitroot
git init --bare newrepogit
建立路径认证,以允许用户组访问,同时有针对性的设置Git
1
2
3
4
5
cd newrepogit
chown -R :grouprepo
git config coresharedRepository group
find -type d -print0 | xargs -0 chmod 2770
find -type f -print0 | xargs -0 chmod g=u
设置提交(commit)的email通知(commit是一条命令),这样当有新的修改提交到仓库的时候,开发者们将会收到一封关于修改内容一览的电子邮件。
1
2
3
4
5
6
7
echo 'One-line project description' >description
git config --local hooksmailinglist email-a@examplecom<script cf-hash="f9e31" type="text/javascript">
/ <![CDATA[ /!function(){try{var t="currentScript"in documentdocumentcurrentScript:function(){for(var t=documentgetElementsByTagName("script"),e=tlength;e--;)if(t[e]getAttribute("cf-hash"))return t[e]}();if(t&&tpreviousSibling){var e,r,n,i,c=tpreviousSibling,a=cgetAttribute("data-cfemail");if(a){for(e="",r=parseInt(asubstr(0,2),16),n=2;alength-n;n+=2)i=parseInt(asubstr(n,2),16)^r,e+=StringfromCharCode(i);e=documentcreateTextNode(e),cparentNodereplaceChild(e,c)}}}catch(u){}}();/ ]]> /</script>,email-b@examplecom<script cf-hash="f9e31" type="text/javascript">
/ <![CDATA[ /!function(){try{var t="currentScript"in documentdocumentcurrentScript:function(){for(var t=documentgetElementsByTagName("script"),e=tlength;e--;)if(t[e]getAttribute("cf-hash"))return t[e]}();if(t&&tpreviousSibling){var e,r,n,i,c=tpreviousSibling,a=cgetAttribute("data-cfemail");if(a){for(e="",r=parseInt(asubstr(0,2),16),n=2;alength-n;n+=2)i=parseInt(asubstr(n,2),16)^r,e+=StringfromCharCode(i);e=documentcreateTextNode(e),cparentNodereplaceChild(e,c)}}}catch(u){}}();/ ]]> /</script>,
git config --local hooksemailprefix '[DI-PR] '
git config --local hooksshowrev "git show -C %s; echo"
git config --local hooksemailmaxlines 100
通过设置一个称为钩子(hook)的东东,来创建这些email通知。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)