root@android-work2:~# addgroup git-group
正在添加组"git-group" (GID 1005)...
完成。
root@android-work2:~# adduser --gid 1005 os-git
正在添加用户"os-git"...
正在添加新用户"os-git" (1003) 到组"git-group"...
创建主目录"/home/os-git"...
正在从"/etc/skel"复制文件...
输入新的 UNIX 密码:
重新输入新的 UNIX 密码:
passwd:已成功更新密码
正在改变 os-git 的用户信息
请输入新值,或直接敲回车键以使用默认值
全名 []:
房间号码 []:
工作电话 []:
家庭电话 []:
其它 []:
这个信息是否正确? [Y/n] y
os-weizb@android-work2:~$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/os-weizb/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/os-weizb/.ssh/id_rsa.
Your public key has been saved in /home/os-weizb/.ssh/id_rsa.pub.
The key fingerprint is:
24:81:e7:80:50:cf:81:b8:a3:df:46:78:3e:23:b7:45 os-weizb@android-work2
The key's randomart image is:
+--[ RSA 2048]----+
|.+.o... |
|. ooo... |
| . o+. . |
|o .o |
|.. . E S |
|. . o. |
| . = . |
| o B. |
| +.+ |
+-----------------+
- Step03 在客户端把公钥复制到服务器上/tmp/目录下
os-weizb@android-work2:~$ scp /home/os-weizb/.ssh/id_rsa.pub 192.168.1.99:/tmp/admin.pub
The authenticity of host '192.168.1.99 (192.168.1.99)' can't be established.
RSA key fingerprint is 71:3e:a1:93:77:e7:1b:72:e1:16:50:9e:f4:c5:e0:c8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.99' (RSA) to the list of known hosts.
[email protected]'s password:
id_rsa.pub
- Step04 在服务端安装gitolite
** 下载官网gitolite源码
root@android-work1:
# git clone git://github.com/ossxp-com/gitolite.git
** 创建目录
root@android-work1:/gitolite#mkdir -p /usr/local/share/gitolite/conf /usr/local/share/gitolite/hooks
** 执行安装
root@android-work1:~/gitolite# ./src/gl-system-install /usr/local/bin /usr/local/share/gitolite/conf /usr/local/share/gitolite/hooks
** 使用git-os专用用户执行安装脚本
root@android-work2:/home/os-git/gitolite/src# su - os-git
os-git@android-work2:~$ gl-setup /tmp/admin.pub
- Step05 在客户端克隆gitolite-admin管理库
os-weizb@android-work2:~$ git clone [email protected]:gitolite-admin
- Step06 在客户端添加,删除用户帐户,设置用户权限
- Step07 在客户端推最新修改到服务器上生效
- 参考资料
下面介绍 Gitolite的部署和使用。在下面的示例中,约定:服务器的名称为 server ,Gitolite的安装帐号为 git ,管理员的 ID 为 admin 。
2.1 安装 Gitolite
Gitolite 要求 git 的版本必须是1.6.2 或以上的版本,并且服务器要提供 SSH 服务。下面是 Gitolite 的安装过程。
2.1.1 服务器端创建专用帐号
安装Gitolite,首先要在服务器端创建专用帐号,所有用户都通过此帐号访问 Git 库。一般为方便易记,选择 git 作为专用帐号名称。
$ sudo adduser --system --shell /bin/bash --group git
创建用户 git,并设置用户的 shell为可登录的 shell,如 /bin/bash,同时添加同名的用户组。
有的系统,只允许特定的用户组(如 ssh用户组)的用户才可以通过 SSH 协议登录,这就需要将新建的 git 用户添加到 ssh 用户组中。
$ sudo adduser git ssh
为 git 用户设置口令。当整个 git服务配置完成,运行正常后,建议取消 git 的口令,只允许公钥认证。
$ sudo passwd git
管理员在客户端使用下面的命令,建立无口令登录:
$ ssh-copy-id git@server
至此,我们已经完成了安装 git服务的准备工作,可以开始安装 Gitolite 服务软件了。
2.1.2 Gitolite的安装/升级
本节的名字称为安装/升级,是因为Gitolite 的安装和升级可以采用下列同样的步骤。
Gitolite安装可以在客户端执行,而不需要在服务器端操作,非常方便。安装 Gitolite 的前提是:
已经在服务器端创建了专有帐号,如 git 。
管理员能够以 git 用户身份通过公钥认证,无口令方式登录方式登录服务器。
安装和升级都可以按照下面的步骤进行:
使用 git 下载 Gitolite 的源代码。
$ git clone git://github.com/ossxp-com/gitolite.git
进入 gitolite/src 目录,执行安装。
$ cd gitolite/src
$ ./gl-easy-install git server admin
命令 gl-easy-install 的第一个参数 git 是服务器上创建的专用帐号ID,第二个参数 server 是服务器IP或者域名,第三个参数 admin 是管理员ID。
首先显示版本信息。
======================================
you are upgrading (or installing first-time) to v1.5.4-22-g4024621
Note: getting '(unknown)' for the 'from' version should only happen once.
Getting '(unknown)' for the 'to' version means you are probably installing
from a tar file dump, not a real clone. This is not an error but it's nice to
have those version numbers in case you need support. Try and install from a
clone
自动创建名为 admin 的私钥/公钥对。
gl-easy-install 命令行的最后一个参数即用于设定管理员ID,这里设置为 admin 。
====================================
the next command will create a new keypair for your gitolite access
The pubkey will be /home/jiangxin/.ssh/admin.pub. You will have to choose a
passphrase or hit enter for none. I recommend not having a passphrase for
now, *especially* if you do not have a passphrase for the key which you are
already using to get server access!
Add one using 'ssh-keygen -p' after all the setup is done and you've
successfully cloned and pushed the gitolite-admin repo. After that, install
'keychain' or something similar, and add the following command to your bashrc
(since this is a non-default key)
ssh-add $HOME/.ssh/admin
This makes using passphrases very convenient.
如果公钥已经存在,会弹出警告。
====================================
Hmmm... pubkey /home/jiangxin/.ssh/admin.pub exists; should I just (re-)use it?
IMPORTANT: once the install completes, *this* key can no longer be used to get
a command line on the server -- it will be used by gitolite, for git access
only. If that is a problem, please ABORT now.
doc/6-ssh-troubleshooting.mkd will explain what is happening here, if you need
more info.
自动修改客户端的 .ssh/config 文件,增加别名主机。
即当访问主机 gitolite时,会自动用名为 admin.pub 的公钥,以 git 用户身份,连接服务器
====================================
creating settings for your gitolite access in /home/jiangxin/.ssh/config;
these are the lines that will be appended to your ~/.ssh/config:
host gitolite
user git
hostname server
port 22
identityfile ~/.ssh/admin
上传脚本文件到服务器,完成服务器端软件的安装。
gl-dont-panic 100% 3106 3.0KB/s 00:00
gl-conf-convert 100% 2325 2.3KB/s 00:00
gl-setup-authkeys 100% 1572 1.5KB/s 00:00
...
gitolite-hooked 100% 0 0.0KB/s 00:00
update 100% 4922 4.8KB/s 00:00
=====================================
the gitolite rc file needs to be edited by hand. The defaults are sensible,
so if you wish, you can just exit the editor.
Otherwise, make any changes you wish and save it. Read the comments to
understand what is what -- the rc file's documentation is inline.
Please remember this file will actually be copied to the server, and that all
the paths etc. represent paths on the server!
自动打开编辑器(vi),编辑 .gitolite.rc 文件,编辑结束,上传到服务器。
以下为缺省配置,一般无须改变:
$REPO_BASE=”repositories”;
用于设置 Git服务器的根目录,缺省是 Git 用户主目录下的 repositories 目录,可以使用绝对路径。所有 Git 库都将部署在该目录下。
$REPO_UMASK=0007;#gets you ‘rwxrwx—’
版本库创建使用的掩码。即新建立版本库的权限为 ‘rwxrwx—’。
$GL_BIG_CONFIG=0;
如果授权文件非常复杂,更改此项配置为1,以免产生庞大的授权编译文件。
$GL_WILDREPOS=1;
缺省支持通配符版本库授权。
该配置文件为 perl语法,注意保持文件格式和语法。退出 vi 编辑器,输入 “:q” (不带引号)。
至此完成安装。
2.1.3 关于 SSH 主机别名
在安装过程中,gitolite 创建了名为admin 的公钥/私钥对,以名为 admin.pub 的公钥连接服务器,由 gitolite提供服务。但是如果直接连接服务器,使用的是缺省的公钥,会直接进入 shell。
那么如何能够根据需要选择不同的公钥来连接 git服务器呢?
别忘了我们在前面介绍过的 SSH主机别名。实际上刚刚在安装 gitolite 的时候,就已经自动为我们创建了一个主机别名。 打开 ~/.ssh/config文件,可以看到类似内容,如果对主机别名不满意,可以修改。
host gitolite
user git
hostname server
port 22
identityfile ~/.ssh/admin
即:
像下面这样输入 SSH 命令,会直接进入 shell,因为使用的是缺省的公钥。
$ ssh git@server
像下面这样输入 SSH 命令,则不会进入 shell。因为使用名为 admin.pub 的公钥,会显示 git 授权信息并马上退出。
$ ssh gitolite
2.1.4 其他的安装方法
上面介绍的是在客户端远程安装Gitolite,是最常用和推荐的方法。当然还可以直接在服务器上安装。
首先也要在服务器端先创建一个专用的帐号,如: git 。
$ sudo adduser --system --shell /bin/bash --group git
将管理员公钥复制到服务器上。
管理员在客户端执行下面的命令:
$ scp ~/.ssh/id_rsa.pub server:/tmp/admin.pub
服务器端安装 Gitolite。
推荐采用源码方式安装,因为如果以平台自带软件包模式安装 Gitolite,其中不包含我们对 Gitolite 的改进。
从源码安装。
使用 git 下载 Gitolite的源代码。
$ git clone git://github.com/ossxp-com/gitolite.git
创建目录。
$ sudo mkdir -p /usr/local/share/gitolite/conf /usr/local/share/gitolite/hooks
进入 gitolite/src目录,执行安装。
$ cd gitolite/src
$ sudo ./gl-system-install /usr/local/bin /usr/local/share/gitolite/conf /usr/local/share/gitolite/hooks
采用平台自带的软件包安装。
例如在 Debian/Ubuntu平台,执行下面命令:
$ sudo aptitude install gitolite
Redhat 则使用 yum命令安装。
在服务器端以专用帐号执行安装脚本。
例如服务器端的专用帐号为 git。
$ sudo su - git
$ gl-setup /tmp/admin.pub
管理员在客户端,克隆 gitolite-admin 库
$ git clone git@server:gitolite-admin
升级 Gitolite:
只需要执行上面的第3个步骤即可完成升级。
如果修改或增加了新的了钩子脚本,还需要重新执行第4个步骤。
Gitolite升级有可能要求修改配置文件: ~/.gitolite.rc 。