安装参考: http://zengrong.net/post/1720.htm http://blog.chinaunix.net/uid-15174104-id-3843570.html git使用参考: Git的思想和基本工作原理 http://www.nowamagic.net/academy/detail/48160210 Git 教程 http://www.runoob.com/git/git-tutorial.html
1、安装git
[root@host1 ~]# yum install git 安装git 有时yum无法安装,则可下载git源码:wget https://www.kernel.org/pub/software/scm/git/git-2.7.0.tar.xz 或gz后缀 在解压后的目录执行:./configure && make && make install 进行安装,默认安装到/usr/local/share/git目录,可通过./configure --help 查看修改配置的命令2、增加用户及组[root@host1 ~]# groupadd git 添加用户组git [root@host1 ~]# useradd -g git git 添加用户git [root@host1 ~]# passwd git 修改git用户的密码3、生成公钥和私钥对[root@host1 ~]# su - git 切换到git用户
[git@host1 ~]$ ssh-keygen 生成公钥和私钥 Generating public/private rsa key pair. Enter file in which to save the key (/home/git/.ssh/id_rsa): 此处的值是输入的文件名称(可以直接回车) Enter passphrase (empty for no passphrase): 此处输入密码,可以不输入。如果输入了,此密码在后续使用私钥时需要输入。 Enter same passphrase again: Your identification has been saved in id_rsa. Your public key has been saved in id_rsa.pub. The key fingerprint is: a7:b0:c2:e5:60:ab:d2:97:ab:41:b9:9a:6a:82:6c:41 wangshichun@host1 The key's randomart image is: +--[ RSA 2048]----+ | | | | | | | E . | |. o o o S . | | o + = o o | |o.+ +.o . | |+*.oo. | |O.oo.. | +-----------------+ [git@host1 ~]$4、安装git服务器
[git@host1 ~]$ git clone git://github.com/sitaramc/gitolite 下载git服务器的源码 [git@host1 ~]$ mkdir bin [git@host1 ~]$ ./gitolite/install -to ~/bin/ [git@host1 ~]$ cd gitolite/ 进入安装目录 [git@host1 gitolite]$ ./src/gitolite setup -h 查看安装说明 [git@host1 gitolite]$ ./src/gitolite setup --pubkey ~/.ssh/id_rsa.pub 设置管理员公钥,并自动设置服务器
5、给用户加权限首先 配置邮箱和名字(在服务器上的git用户下)git config --global user.name '王世春' git config --global user.email 'wangshichun@xxx.com'创建一个目录(位置随意),然后克隆权限配置项目到该目录中。git clone ssh://git@host1/gitolite-admin.gitcd gitolite-admin此时,conf文件夹下有一个 gitolite.conf文件, keydir下是用户的公钥。gitolite.conf文件示例如下。 第一行中的“@developer”表示developer是一个人员分组,该分组下的人员名称是空格分隔的姓名。 这里的姓名和keydir文件夹中的名称一一对应。 在这里有一个姓名,则在keydir中就有一个对应该姓名的“.pub”结尾的文件,文件中的内容是该用户的公钥。
该文件中的“repo”开头的行是定义工程项目的,repo后面是一个空格,和项目名称。 可以用斜杠表示项目的分组。 repo开头的行下方的行定义该项目的权限。权限定义中,等号左边是权限(RW+表示读写等),右边是人员或者人员分组的名称。 ========conf/gitolite.conf文件示例开始============================== @developer = wangshichun id_rsa repo gitolite-admin RW+ = id_rsa repo testing RW+ = @all repo other/otherProject RW+ = @developer
对应的克隆地址分别为: ssh://git@host1/testing.git ssh://git@host1/other/otherProject.git 以此类推 如果有新的工程需要增加,则直接在gitolite.conf文件增加一个repo即可。 增加用户或项目后,需要将内容进行提交。 git add conf/gitolite.conf (增加用户、项目、修改权限时均需要) git add keydir/wangshichun.pub (增加用户并设置公钥的时候需要) git commit -m 'commit message: add user or project' git push
安装GIT服务器 gitolite,及权限管理
最新推荐文章于 2018-06-27 14:28:08 发布