Gitosis is a tool which provides access control and remote management for hosted [[Git]] repositories. It allows for fine-grained management of read and write access over SSH, without requiring that the users have local system accounts on the server. To do this, it sets up a single system account "{{ic|git}}" which is then used for all Git access.

−

gitosis is simply an access control list for git, the (famous) stupid content tracker. Once you have a git repository, there are many ways to setup how people will access it. You might prefer publishing your repository with read-only access via the git:// protocol. But when it comes to pushing to the repository, it's essential to decide by whom and how the repository will be accessed. Generally, you wouldn't prefer letting everyone pushing changes and hopefully ruin your repository. Therefore you need some kinds of authorization methods such as:

+

Gitosis provides installation instructions in its [http://eagain.net/gitweb/?p=gitosis.git;a=blob;f=README.rst;hb=HEAD README] file. This guide is based on those instructions.

−

* SSH Authentication

+

== Installation and setup ==

−

* HTTP Authentication (webdav)

+

−

* gitosis (using SSH)

+

−

The rest of this document is about the third method. (Afterall, the title says it all.)

+

Install the [https://aur.archlinux.org/packages.php?ID=23419 gitosis-git] package from the [[AUR]]. This will create three things:

+

* the {{ic|git}} user

+

* the {{ic|git}} group to which this user belongs

+

* the {{ic|/srv/gitosis}} directory, which will hold data and repositories for Gitosis

−

== What does gitosis do? ==

+

To configure Gitosis, you do not edit files directly on the server. Instead, Gitosis provides a Git repository which contains the configuration. To update this configuration, you clone, commit, and push to {{ic|gitosis-admin}} just as you would any other repository.

−

+

−

With gitosis, you have the ability to pull from and push to the repository with just one system account. You don't need to create SSH accounts for each user who will have write access to the repository. Once you install the package (see below), there will be system user created on your system called gitosis with a home directory in /srv. Users that will access to the repositories will be using gitosis user for every transaction.

+

−

+

−

= Installation =

+

−

Install [http://aur.archlinux.org/packages.php?ID=23419 gitosis-git] from the [[AUR]].

+

−

+

−

Once installed, you'll be able to find some example config files in ''/usr/share/doc/gitosis''.

+

−

+

−

== Initiating gitosis-admin repository ==

+

−

+

−

You will need a public SSH key to continue. If you don't have one, you may generate one on your local computer:

+

+

Since Gitosis uses [[SSH keys]] to authenticate users, you will need to generate a keypair to use for the administrative repository. If you do not have one, you can generate it using {{ic|ssh-keygen}}, for example:

$ ssh-keygen -t rsa

$ ssh-keygen -t rsa

−

In order to make gitosis work, you should first create a SSH key pair (or use the existing one) and use the public key to create the gitosis-admin repository installed within gitosis home directory (''/srv/gitosis'').

You should also place the public key you used above as '''.ssh/authorized_keys''' inside gitosis' home directory. The above command will create two directories:

+

{{

+

note|In some cases, this might result in an error of this kind:

−

* gitosis

+

OSError: [Errno 13] Permission denied: '//gitosis'

−

* repositories

+

−

The directory gitosis includes a single file (''projects.list'') in which some information about the repositories are defined. The repositories directory contains all repositories including the gitosis-admin repository.

+

The cause of this might be that the git home directory was not set properly.

+

Fix it by setting it manally:

−

== gitosis-admin repository ==

+

# usermod -d /srv/gitosis git

+

}}

−

gitosis-admin is simply a git repository, that stores the permissions per repository and the keys of users who have access to them. To change the settings of gitosis, add/remote repositories or users, you'll need to clone the repository to some local directory and do the changes like you would do to a normal git repository. After you're done with the files, you'll have to commit the changes and push them to the remote repository you initially cloned from.

+

In addition, this command creates the directory {{ic|/srv/gitosis/repositories}} in which the actual hosted repositories will be stored.

−

$ git clone git@host:gitosis-admin.git

+

After the initialisation of the admin repository is complete, it might be sensible to disable the password based ssh login of the user git.

* {{ic|keydir}} &ndash; directory containing public keys for each user

+

+

To modify repositories or users, or to configure Gitosis, just commit changes in your clone and push them back to the server.

+

+

=== Repositories and permissions ===

+

+

You'll be able to find some example configuration files in ''/usr/share/doc/gitosis''.

[gitosis]

[gitosis]

Line 70:

Line 67:

[repo foobar]

[repo foobar]

−

description = git repository for foobar

+

description = Git repository for foobar

owner = user

owner = user

Line 90:

Line 87:

writable = free_monkey

writable = free_monkey

members = jdoe

members = jdoe

+

+

[group deployer]

+

writable = free_monkey

+

readonly = monkey_deployer

−

This defines a new group called "free_monkey", which is an arbitrary string. "jdoe" is a member of myteam and will have write access to the "gitosis" repo.

+

This defines a new group called "free_monkey", which is an arbitrary string. "jdoe" is a member of myteam and will have write access to the "gitosis" repository. The "monkey_deployer" key will have only read-only access to "free_monkey".

Save this addition to gitosis.conf, commit and push it:

Save this addition to gitosis.conf, commit and push it:

Line 98:

Line 99:

$ git push

$ git push

−

Now the user "jdoe" has access to write to the repo named "free_monkey", but we still haven't created a repo yet. What we will do is create a new repo locally, and then push it:

+

Now the user "jdoe" has access to write to the repository named "free_monkey", but we still have not created a repository yet. What we will do is create a new repository locally, initialize it on the Git server, and then push it:

$ mkdir free_monkey

$ mkdir free_monkey

Line 109:

Line 110:

$ git push origin master:refs/heads/master

$ git push origin master:refs/heads/master

−

With the final push, you're off to the races. The repository "free_monkey" has been created on the server (in /srv/gitosis/repositories) and you're ready to start using it like any ol' git repo.

+

When using SSH, the last command will fail with the error message "does not appear to be a Git repository"

+

This can be fixed by initializing the repository manually on the server

+

$ git init --bare /srv/gitosis/repositories/free_monkey.git

−

gitosis repositories can also be used with gitweb; just point the directory that contains the repository inside the gitweb configuration.

+

and retry the last command

−

== Adding users ==

+

With the final push, you are off to the races. The repository "free_monkey" has been created on the server (in /srv/gitosis/repositories) and you are ready to start using it like any ol' Git repository.

−

The next natural thing to do is to grant some lucky few commit access to the FreeMonkey project. This is a simple two step process.

+

Gitosis repositories can also be used with gitweb; just point the directory that contains the repository inside the gitweb configuration.

+

+

=== Adding users ===

+

+

The next natural thing to do is to grant a lucky few commit access to the FreeMonkey project. This is a simple two step process.

First, gather their public SSH keys, which I'll call "alice.pub" and "bob.pub", and drop them into keydir/ of your local gitosis-admin repository. Second, edit gitosis.conf and add them to the "members" list.

First, gather their public SSH keys, which I'll call "alice.pub" and "bob.pub", and drop them into keydir/ of your local gitosis-admin repository. Second, edit gitosis.conf and add them to the "members" list.

Line 143:

Line 150:

Alice and Bob will also have commit rights.

Alice and Bob will also have commit rights.

−

== Public access ==

+

=== Public access ===

−

If you are running a public project, you will have your users with commit rights, and then you'll have everyone else. How do we give everyone else read-only access without fiddling w/ SSH keys?

+

If you are running a public project, you will have your users with commit rights, and then you'll have everyone else. How do we give everyone else read-only access without fiddling with SSH keys?

−

We just use git-daemon. This is independent of gitosis and it comes with git itself.

+

We just use git-daemon. This is independent of Gitosis and it comes with Git itself.

This will make all the repositories you manage with gitosis read-only for the public. Someone can then clone FreeMonkey like so:

+

This will make all the repositories you manage with Gitosis read-only for the public. Someone can then clone FreeMonkey like so:

$ git clone git://YOUR_SERVER_HOSTNAME/free_monkey.git

$ git clone git://YOUR_SERVER_HOSTNAME/free_monkey.git

−

To export only some repositories and not others, you need to touch git-daemon-export-ok inside the root directory (e.g. /srv/gitosis/repositories/free_monkey.git) of each repo that you want public. Then remove "--export-all" from the git-daemon command above.

+

To export only some repositories and not others, you need to touch git-daemon-export-ok inside the root directory (e.g. /srv/gitosis/repositories/free_monkey.git) of each repository that you want public. Then remove "--export-all" from the git-daemon command above.

−

== More tricks ==

+

=== More tricks ===

+

+

gitosis.conf can be set to do some other neat tricks. Open example.conf in the Gitosis source directory (where you originally cloned Gitosis way at the top) to see a summary of all options. You can specify some repositories to be read-only (opposite of writable), but yet not public. A group members list can include another group. And a few other tricks that I'll leave it to the reader to discover.

−

gitosis.conf can be set to do some other neat tricks. Open example.conf in the gitosis source directory (where you originally cloned gitosis way at the top) to see a summary of all options. You can specify some repos to be read-only (opposite of writable), but yet not public. A group members list can include another group. And a few other tricks that I'll leave it to the reader to discover.

Caveats

Caveats

−

If /srv/gitosis/.gitosis.conf on your server never seems to get updated to match your local copy (they should match), even though you are making changes and pushing, it could be that your post-update hook isn't executable. Older versions of setuptools can cause this. Be sure to fix that:

+

If /srv/gitosis/.gitosis.conf on your server never seems to get updated to match your local copy (they should match), even though you are making changes and pushing, it could be that your post-update hook is not executable. Older versions of setuptools can cause this. Be sure to fix that:

If your Python goodies are in a non-standard location, you must additionally edit post-update and put an "export PYTHONPATH=..." line at the top. Failure to do so will give you a Python stack trace the first time you try to push changes within gitosis-admin.

If your Python goodies are in a non-standard location, you must additionally edit post-update and put an "export PYTHONPATH=..." line at the top. Failure to do so will give you a Python stack trace the first time you try to push changes within gitosis-admin.

−

If you want to install gitosis in a non-standard location, I don't recommend it. It's an edge case that the author hasn't run up against until I bugged him to help me get it working.

+

If you want to install Gitosis in a non-standard location, I do not recommend it. It's an edge case that the author has not run up against until I bugged him to help me get it working.

For the brave, you need to edit whatever file on your system controls the default PATH for a non-login, non-interactive shell. On Ubuntu this is /etc/environment. Add the path to gitosis-serve to the PATH line. Also insert a line for PYTHONPATH and set it to your non-standard Python site-packages directory. As an example, this is my /etc/environment:

For the brave, you need to edit whatever file on your system controls the default PATH for a non-login, non-interactive shell. On Ubuntu this is /etc/environment. Add the path to gitosis-serve to the PATH line. Also insert a line for PYTHONPATH and set it to your non-standard Python site-packages directory. As an example, this is my /etc/environment:

Line 177:

Line 185:

Be sure to logout and log back in after you make these changes.

Be sure to logout and log back in after you make these changes.

−

Don't use the gitosis-init line I have above for the standard install, instead use this slightly modified one:

+

Do not use the gitosis-init line I have above for the standard install, instead use this slightly modified one:

$ sudo -H -u git env PATH=$PATH gitosis-init < /tmp/id_rsa.pub

$ sudo -H -u git env PATH=$PATH gitosis-init < /tmp/id_rsa.pub

Line 183:

Line 191:

Be sure to also set PYTHONPATH in your post-update hook as described above.

Be sure to also set PYTHONPATH in your post-update hook as described above.

−

The *should* do it. I am purposefully terse with this non-standard setup as I think not many people will use it. HIt me up in #git on FreeNode if you need more info (my nick is up_the_irons).

+

That *should* do it. I am purposefully terse with this non-standard setup as I think not many people will use it. Hit me up in #git on FreeNode if you need more information (my nick is up_the_irons).

−

== Non-standard SSH port ==

+

=== Non-standard SSH port ===

−

If you run SSH on a non-standard port on your server, don't use the syntax "git@myserver.com:1234:/foo/bar", it won't work. Putting the port in the URL doesn't seem to make gitosis, or git, (not sure which) happy. Instead, put this in your ~/.ssh/config file:

+

If you run SSH on a non-standard port on your server, there are two ways of specifying on which port Git will try to connect. One is to explicitly state that you are using the SSH protocol, as this lets you put

+

in a port number in the URL too:

+

+

git clone ssh://git@myserver.com:1234/repo.git

+

+

Or you can put this in your ~/.ssh/config file:

$ Host myserver.com

$ Host myserver.com

Line 200:

Line 213:

You should commit and push any changes you do in this file.

You should commit and push any changes you do in this file.

−

== keydir ==

+

=== keydir ===

+

+

keydir is simply a directory that contains public keys of the users. Some of the keys can be in the form of user@machine and those keys must be defined with that form inside gitosis.conf. It's better to create user groups and use them as members of the repositories. Once you add new keys to enable some new users, you should add the files to the Git repository and commit and push them. The new users will use the above form of Git commands like you have used to clone the gitosis-admin repository.

−

keydir is simply a directory that contains public keys of the users. Some of the keys can be in the form of user@machine and those keys must be defined with that form inside gitosis.conf. It's better to create user groups and use them as members of the repositories. Once you add new keys to enable some new users, you should add the files to the git repository and commit & push them. The new users will use the above form of git commands like you've used to clone the gitosis-admin repository.

+

== See also ==

+

* [http://eagain.net/gitweb/?p=gitosis.git Gitosis source]

+

* [[Gitolite]] &ndash; an alternative to Gitosis which provides many similar features

Revision as of 16:48, 18 October 2012

Reason:please use the first argument of the template to provide a brief explanation. (Discuss in Talk:Gitosis#)

Gitosis is a tool which provides access control and remote management for hosted Git repositories. It allows for fine-grained management of read and write access over SSH, without requiring that the users have local system accounts on the server. To do this, it sets up a single system account "git" which is then used for all Git access.

Gitosis provides installation instructions in its README file. This guide is based on those instructions.

Contents

Installation and setup

Install the gitosis-git package from the AUR. This will create three things:

the git user

the git group to which this user belongs

the /srv/gitosis directory, which will hold data and repositories for Gitosis

To configure Gitosis, you do not edit files directly on the server. Instead, Gitosis provides a Git repository which contains the configuration. To update this configuration, you clone, commit, and push to gitosis-admin just as you would any other repository.

Since Gitosis uses SSH keys to authenticate users, you will need to generate a keypair to use for the administrative repository. If you do not have one, you can generate it using ssh-keygen, for example:

This defines a new group called "free_monkey", which is an arbitrary string. "jdoe" is a member of myteam and will have write access to the "gitosis" repository. The "monkey_deployer" key will have only read-only access to "free_monkey".

Now the user "jdoe" has access to write to the repository named "free_monkey", but we still have not created a repository yet. What we will do is create a new repository locally, initialize it on the Git server, and then push it:

When using SSH, the last command will fail with the error message "does not appear to be a Git repository"
This can be fixed by initializing the repository manually on the server

$ git init --bare /srv/gitosis/repositories/free_monkey.git

and retry the last command

With the final push, you are off to the races. The repository "free_monkey" has been created on the server (in /srv/gitosis/repositories) and you are ready to start using it like any ol' Git repository.

Gitosis repositories can also be used with gitweb; just point the directory that contains the repository inside the gitweb configuration.

Adding users

The next natural thing to do is to grant a lucky few commit access to the FreeMonkey project. This is a simple two step process.

First, gather their public SSH keys, which I'll call "alice.pub" and "bob.pub", and drop them into keydir/ of your local gitosis-admin repository. Second, edit gitosis.conf and add them to the "members" list.

To export only some repositories and not others, you need to touch git-daemon-export-ok inside the root directory (e.g. /srv/gitosis/repositories/free_monkey.git) of each repository that you want public. Then remove "--export-all" from the git-daemon command above.

More tricks

gitosis.conf can be set to do some other neat tricks. Open example.conf in the Gitosis source directory (where you originally cloned Gitosis way at the top) to see a summary of all options. You can specify some repositories to be read-only (opposite of writable), but yet not public. A group members list can include another group. And a few other tricks that I'll leave it to the reader to discover.

Caveats

If /srv/gitosis/.gitosis.conf on your server never seems to get updated to match your local copy (they should match), even though you are making changes and pushing, it could be that your post-update hook is not executable. Older versions of setuptools can cause this. Be sure to fix that:

If your Python goodies are in a non-standard location, you must additionally edit post-update and put an "export PYTHONPATH=..." line at the top. Failure to do so will give you a Python stack trace the first time you try to push changes within gitosis-admin.

If you want to install Gitosis in a non-standard location, I do not recommend it. It's an edge case that the author has not run up against until I bugged him to help me get it working.

For the brave, you need to edit whatever file on your system controls the default PATH for a non-login, non-interactive shell. On Ubuntu this is /etc/environment. Add the path to gitosis-serve to the PATH line. Also insert a line for PYTHONPATH and set it to your non-standard Python site-packages directory. As an example, this is my /etc/environment:

Do not use the gitosis-init line I have above for the standard install, instead use this slightly modified one:

$ sudo -H -u git env PATH=$PATH gitosis-init < /tmp/id_rsa.pub

Be sure to also set PYTHONPATH in your post-update hook as described above.

That *should* do it. I am purposefully terse with this non-standard setup as I think not many people will use it. Hit me up in #git on FreeNode if you need more information (my nick is up_the_irons).

Non-standard SSH port

If you run SSH on a non-standard port on your server, there are two ways of specifying on which port Git will try to connect. One is to explicitly state that you are using the SSH protocol, as this lets you put
in a port number in the URL too:

[repo] blocks are used to define some necessary areas being used with gitweb.

[group] blocks are used for both:

defining user groups

defining repository permissions

@ is used to define user groups.

You should commit and push any changes you do in this file.

keydir

keydir is simply a directory that contains public keys of the users. Some of the keys can be in the form of user@machine and those keys must be defined with that form inside gitosis.conf. It's better to create user groups and use them as members of the repositories. Once you add new keys to enable some new users, you should add the files to the Git repository and commit and push them. The new users will use the above form of Git commands like you have used to clone the gitosis-admin repository.