Managing Repositories on Git Server Using Gitosis
How to manage users and repositories and how to use these repositories will be introduced in this post. Please refer to Setting Up Git Server Using Gitosis for how to set up the git server. Please refer to Howto for New Git User for how to use git as a new user.
Create a new user
Now let’s see how to create a new user user1.
First the new user user1 generates his/her public SSH key and copies or emails the public part of its SSH key to the administrator (we copy to /tmp/user1.pub in this example):
$ ssh-keygen -t rsa $ cp ~/.ssh/id_rsa.pub /tmp/user1.pub
Then the administrator copies use1‘s public SSH key to the keydir directory in the gitosis-admin repository on the administrator’s local machine:
$ cp /tmp/user1.pub keydir/
Add to the gitosis-admin repository
$ git add keydir/user1.pub
Commit the changes
$ git commit -a -m 'user user1 is added'
Push to the git server
$ git push
After this administrator pushing the new commit, user1 has been added to gitosis on the git server. The name of the user’s public SSH key file is in this format:
user1.pub
Please note that the name of the file should be the same as the user name. For example, the public key file for user1 should be user1.pub .
Create a new repository record in configuration file
All the operations in this part is done by administrator on it’s local machine.
We add a new repository named gitosis-test. In the configuration file, we add a new group gitosis-test-group and we add user1 to it’s members list. This group can write to gitosis-test repository, so that user1 can write to this repository. As described before, add these lines to gitosis.conf file:
[group gitosis-test-group] writable = gitosis-test members = user1
We can also grant readonly access to this repository to a group of users as follows:
[group gitosis-test-readonly-group] readonly = gitosis-test members = readuser1 readuser2
Then commit and push the changes to the server:
$ git commit -a -m 'config for new repository gitosis-test is added' $ git push
By now, the new repository record has been added in the configuration file. User user1 is granted write privilege to it. If we want to add another user such as user2 to gitosis-test-group, just make this change:
- members = user1 + members = user1 user2
Create and use the repository
The user1 can create the repository by itself following the introduction in Howto for New Git User.
Updated history
May. 4, 2010. Add how to continue using the original copy. Jul. 16, 2010. Update “use repository” part and add two useful links. Jul. 26, 2010. Add “key pairs” part. Aug. 7, 2010. Add “readonly” introduction. Oct. 11, 2011. Update the writing and adapts for anagement only. Nov. 22, 2011. Update writing.
Tags: Fedora, Git, Server config, Tutorial
One important point – you should use the same id (username or username@) in both the gitosis.conf file, and for the name of the keyfile in keydir, but latter should have .pub prefix. For example, filename user@example.com.pub, then user@example.com should be specified in that file, and then user@example.com should be used in gitosis.conf
That’s true. Thanks for point it out here.
@Rafael Souza:
I never try “agent forward” when using gitosis. From my experience, “asking password” is related to private key. My suggestion is try to check the ~/.ssh directory of your account and the second dev’s on the VPS. That may cause the difference.
Hi
Great post, helped me a lot! :)
But I am with a problem when one of my devs try to clone on our VPS. let me try to ilustrate the scenario.
I am the administrator of the git server, I did the configuration using my ssh key. I can clone repos on my machine and on the vps using ssh “agent forward”. the second dev is able to clone/pull/push on his machine but not on the same vps, even using “agent forward”, it’s stay asking his password.
Do know what could be wrong?
Thanks and keep posting good stuff :)