Setting Up Git Server Using Gitosis

本文介绍如何使用Gitosis软件在服务器上搭建Git版本控制系统。Gitosis允许管理员为不同用户提供不同的读写权限,并简化了用户及仓库管理流程。通过设置特殊仓库gitosis-admin.git进行配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Gitosis is a software for hosting git repositories witten by Tommi Virtanen. It manages multiple repositories under the same user account. It uses SSH public keys to identify users. Users do not need shell accounts on the git server. The operations are done under the shared account.

One benefit we can get from gitosis is that we can give different suers different write/read rights over different repositories. Another benefit is easier user and repository management. The management is done by a special repository named gitosis-admin.git on the server.

Let’s look at how to set up a git server using gitosis. Here we want to set up a git server on example.org. Please refer to Managing Repositories on Git Server Using Gitosis for how to manage and use the repositories managed by gitosis.

Install git and gitosis on server

First , logon to the git server by “ssh username@example.org”. username is the account name that can sudo or the user who knows root’s password to use su on the git server.

Then install gitos and git. On fedora system the command is like this:

$ sudo yum install git gitosis

or

$ su -c 'yum install git gitosis'

The command may be different on the other platforms.

Create server side git user and home

We need to create a Linux account for the shared account. It is usually git. But any account name can be used. The repositories are stored in git’s home directory.

Logon to the git server by ssh username@example.org. username is the account name that can sudo or the one that knows root’s password on the git server.

$ sudo useradd -m -d /home/git -u 1005 git

Here we assume git’s home directory is /home/git.

Setup gitosis management repository

First create the administrator’s SSH public key if you haven’t got one. On the administrator’s local machine:

$ ssh-keygen -t rsa

Then copy it to the git server’s /tmp/ directory:

$ scp ~/.ssh/id_rsa.pub username@example.org:/tmp/id_rsa.pub

Logon to the git server with account that has privilege to sudo or su. Then:

$ sudo su - git
$ cd
$ gitosis-init < /tmp/id_rsa.pub

Now we have created the gitosis administration repository on git server. The default repository directory is ~/repositories/ under git’s home directory.

Then the administrator can get the gitosis-admin repository from the git server on local machine:

$ git clone git@example.org:gitosis-admin.git

There are one configuration file and one directory in gitosis-admin:

gitosis.conf  keydir

gitosis.conf is the configuration file for gitosis. keydir is used to store the users’ public SSH keys. These files are used to manage repositories and users by the administrator. A git server has been set up by now. Management work can be done by editing the files in the gitosis-admin repository and pushing it to the git server.

Public access

We may want to  give everyone read-only access to a public project without using SSH keys. We can use git-daemon. It is a daemon tool independent of gitosis and it comes with git itself.

First logon to the git server as privileged user, and then use this command to export all the repositories to public users.:

$ sudo -u git git-daemon --base-path=/home/git/repositories/ --export-all

Someone can then clone repository example.git like this:

$ git clone git://example.org/example.git

If we only want to export selected repositories, we should remove “–export-all” from the above command. Then if we want to export example.git to the others, we need to logon the git server (privileged account is needed) and go to the repository’s directory (/home/git/repositories/example.git for this example). Then create a file named git-daemon-export-ok:

$ touch git-daemon-export-ok

Then this repository is exported to the public now, while the others are keep private.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值