GIT Server Installation Procedure

Step 1 – (On your server)
Install python-setuptools on your server, you’ll need it to install gitosis.
As root:

Step 2 – (On your server)
As root:

Step 3 – (On your server)
Install gitosis.
As root:

(it should download stuff and create a gitosis directory)

Step 4 – (On your server)
Make a user called git.

Give your new user git a password.

Step 5 – (On your client)
The whole point of gitosis is to transfer files via ssh using a shared key process (ie: no password required to login to user git on your server). Now before you go and start doing it the manual way – don’t. Gitosis must create and maintain the authorized_keys file.
As your normal user on your client/development box:

There is now a new file called id_rsa.pub in ~/.ssh/
Copy the id_rsa.pub file to the server:

Step 6 – (On your server)
I’m assuming you’re still root on the server.
Change to the git user.

It should reply with Initialized empty Git repository in ./ – twice..
We can now remove id_rsa.pub as we don’t need it anymore.

Now we must set some directory and file permissions to let sshd see the new authorized_keys file.

Step 7 – (On your client)
We’re pretty much done server side. Now we’re going to configure the server via the client.
Although I assume this is obvious, you need to install git on your client machine.

You should see a gitosis.conf file and keydir directory. Here’s the thing, anything you need to configure on the server, you actually configure here and commit the changes to the server. Open up gitosis.conf in your favorite text editor
Make a new group name for your project. It really doesn’t matter what you name this group. Add users to the member section who will need push access.

Save the file. Why did we use that members=user@someServer.com? If you look in the keydir directory, you’ll see your public key with the filename user@someServer.com.pub. These are your users (minus the .pub).
Step 8 – (On your client)
You’ve just made a configuration change. You want the server to allow user@someServer.com to have write access to a project called myNewProject. You must commit this change to the server.

Now it’s time to make the directory that will contain your project files. Move up out of the gitosis-admin directory.

Add your files, move some files, create some files. Put some files in the myNewProject directory.
Now we can commit the initial push to the server.

Git will do some neat things and push things to the server. Now to delete the directory you just created.. Yeah, I said it.

And now to pull myNewProject from the server using clone..

Now you have a version of your code you can actually use, make changes and commit to the server using normal git commands.
As of now, you have a fully functioning git server with a project and a client that can make changes. But what about other people?
Step 9 – (On your client)
So your friend Bob wants to help you out with myNewProject. Have Bob generate his own id_rsa.pub and send it you. When you have it:

Assuming Bob’s id_rsa.pub is in your home directory, move it to the key directory renaming it at the same time:

Tell git about the new file:

Edit your gitosis.conf file again. Look for the members line in myNewProject and add Bob to it:

Now you could add bob to be in the gitosis-admin group if you wanted him to be able to do what you’re doing now. How much do you trust Bob?
Save the file and quit. It’s time to tell your server about Bob and send Bob’s public key.

The server will automatically add Bob’s public key to authorized_keys. Do not attempt to add him manually.

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS
The following two tabs change content below.

Tapas Mishra

Sr. Engineer (DevOps)
Loves to work on Opensource products. Having experience on Linux environment. Knowledge on Public cloud services like AWS, Rackspace, DigitalOcean, Linode. Please don't hesitate to give a comment on the posts. Your comments are my strength.

3 thoughts on “GIT Server Installation Procedure

Leave a Reply