当前位置: 首页 > 工具软件 > Gitosis > 使用案例 >

git 配置gitosis_使用Gitosis设置Git服务器

齐献
2023-12-01

git 配置gitosis

Update: Since gitosis is not maintained and supported, please check out gitolite for setting up a new git server. (see the comment from Sitaram Chamarty, the gitolite author, the author of gitolite.)

更新:由于不维护和不支持gitosis,请检出gitolite来设置新的git服务器。 (请参见gitolite作者gitolite的作者Sitaram Chamarty的评论。)



Gitosis is a piece of software writen by Tommi Virtanen for hosting git repositories. 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.

Gitosis是Tommi Virtanen编写的用于托管git存储库的软件。 它在同一用户帐户下管理多个存储库。 它使用SSH公钥来标识用户。 用户不需要git服务器上的shell帐户。 该操作在共享帐户下完成。

One benefit we get from using gitosis is that we can give different users write/read right on 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.

使用gitosis的好处之一是,我们可以使不同的用户在不同的存储库上进行写/读操作。 另一个好处是用户和存储库管理更加轻松。 管理由服务器上名为gitosis-admin.git的特殊存储库完成。

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 and Howto for New Git Users for how to manage and use the repositories managed by gitosis.

让我们看看如何使用gitosis设置git服务器。 在这里,我们要在example.org上设置一个git服务器。 有关如何管理和使用由gitosis 管理的存储库,请参阅使用Gitosis在Git服务器上管理存储库针对新Git用户的操作方法。

在服务器上安装git和gitosis (Install git and gitosis on the server)

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

首先,通过“ ssh username@example.org”登录git服务器。 用户名是帐户名,可以包括sudo或用户知道root的git的服务器上的密码。

Then install gitosis and git. On the Fedora system, the command is like this:

然后安装gitosis和git。 在Fedora系统上,命令如下:

$ sudo yum install git gitosis

or

要么

$ su -c 'yum install git gitosis'

The command may be different on the other platforms.

该命令在其他平台上可能会有所不同。

创建服务器端git用户和主目录 (Create the 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.

我们需要为共享帐户创建一个Linux帐户。 通常是git。 但是可以使用任何帐户名。 存储库存储在git的主目录中。

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.

通过ssh username@example.org登录git服务器。 username是可以sudo的帐户名,也可以是知道git服务器上root密码的帐户名。

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

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

这里我们假设git的主目录是/ home / git。

设置gitosis管理存储库 (Setup gitosis administration repository)

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

如果您还没有,请首先创建管理员的SSH公钥。 在管理员的本地计算机上:

$ ssh-keygen -t rsa

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

然后将其复制到git服务器的/ tmp /目录:

$ 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服务器。 然后:

$ 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.

现在,我们在git服务器上创建了gitosis管理存储库。 默认的存储库目录是git的主目录下的〜/ repositories /。

Then the administrator can clone the gitosis-admin repository on  its local machine:

然后,管理员可以在其本地计算机上克隆gitosis-admin存储库:

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

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

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.

gitosis.conf是gitosis的配置文件。 keydir用于存储用户的公共SSH密钥。 这些文件由管理员用来管理存储库和用户。 到此为止,已经建立了一个git服务器。 通过编辑gitosis-admin存储库中的文件并将其推送到git服务器,可以完成管理工作。

公共访问 (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.

我们可能希望为每个人提供对公共项目的只读访问权限,而不使用SSH密钥。 我们可以使用git-daemon。 这是一个独立于gitosis的守护程序工具,它​​本身带有git。

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

首先以特权用户身份登录git服务器,然后使用此命令将所有存储库导出到公共用户。

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

Someone can then clone repository example.git like this:

然后,有人可以像这样克隆存储库example.git:

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

Note the difference of the repository address.

注意存储库地址的不同。

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 log on the git server (privileged account is needed), go to the repository’s directory (/home/git/repositories/example.git for this example),  and create a file named git-daemon-export-ok:

如果只想导出选定的存储库,则应从上述命令中删除“ –export-all”。 然后,如果我们要将example.git导出到其他人,则需要登录git服务器(需要特权帐户),转到存储库的目录(此示例为/home/git/repositories/example.git),然后创建一个名为git-daemon-export-ok的文件:

$ touch git-daemon-export-ok

This repository is exported to the public now, while the others are keep private (if not set to be public).

此存储库现在已导出到公共环境,而其他存储库则保持私有状态(如果未设置为公共)。

翻译自: https://www.systutorials.com/setting-up-git-server-using-gitosis/

git 配置gitosis

 类似资料: