Managing Repositories on Git Server Using Gitosis
Posted on In LinuxHow to manage users and repositories and how to use these repositories will be introduced in this post. Please refer to Setting Up a Git Server Using Gitosis for how to set up the git server. Please refer to Howto for New Git Users 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 Users.