Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I've recently set up ubuntu-server on Amazon EC2. I would like to use it as my git server, so I could store my repos there.

So, where can I find some detailed instructions of how to setup git on ubuntu server? All these SSH keys and stuff like that, multiple users, etc.

share|improve this question
2  
I don't think this is an Ubuntu-related question (beyond the obvious "it's linux"), also have you even looked at the git documentation? There's mentions there of setting up a public as well as a private repository. –  Ward Muylaert Feb 7 '11 at 11:06
2  
Just search on google and here: help.ubuntu.com/community/Git –  BonboBingo Feb 7 '11 at 13:08
18  
@BonboBingo Saying "Just search Google" really isn't a solution. The majority of questions here could be answered with "if you search long enough..." Ask Ubuntu aims to be the authority Question and Answer site providing 1st level answers instead of a wall of answers that say "Just Google" - for more information check the FAQ –  Marco Ceppi Feb 7 '11 at 14:40
1  
There is a useful step guide here: help.ubuntu.com/community/Git. @Marco Ceppi Sorry but I wasn't polemical. And then the link that I had posted seems to be quite relevant to question ... Okay now as an answer? –  BonboBingo Feb 7 '11 at 15:10
2  
"instead of a wall of answers that say "Just Google" - for more information check the"... ok you're right :) Let's stop here. –  BonboBingo Feb 7 '11 at 15:24
show 3 more comments

10 Answers 10

up vote 26 down vote accepted

You can use the tutorial to install a Git server as aking1012 proposed you or you could just install SSH server on your EC2 instance (probably it would be wise to secure it and change the default port).

Git can be server-less you init your repository and then you access it from remote via SSH. So instructions like this on the Ubuntu Server should do it:

GIT_DIR=project.git git init  
cd project.git  
git --bare update-server-info  
cp hooks/post-update.sample hooks/post-update

Finally install SSH on your server:

sudo apt-get install ssh-server

Now, you should configure SSH to secure it.

It's time to put your project online (the data you already have on your development machine):

git push ssh://<username>@<remote-git-hostname>/path/to/project.git master

And now you can start cloning around. You go on your development machine:

git clone ssh://<username>@<remote-git-hostname>/path/to/dir.git

Check this excellent resource on Git.

And for generating your ssh keys for safer authentication, you can read this article about SSH authentication.

share|improve this answer
    
Shouldn't thatbe openssh-server? –  Jorge Castro Nov 12 '10 at 4:32
1  
@jorge it seems that ssh-server is an alias to openssh-server, at least on Ubuntu 10.04. –  Huygens Nov 12 '10 at 7:38
1  
well, this could work, but logging via SSH to Amazon EC2 machines requires public/private keypair (ssh -i key.pem ubuntu@address). Also, I have to remember the path (ubuntu@address:/var/www/dir1/dir2), instead of just git clone git.mydomain.com/repository –  Paweł Karpiński Nov 12 '10 at 8:02
1  
@Pawel good point. That's why some people put the git repository at the file system root. But yes, you need ssh keys or accounts. Or you could use HTTP, but then you don't have really nice access control AFAIK. –  Huygens Nov 12 '10 at 9:56
2  
@PawełKarpiński - You can set up a client-side SSH config file in ~/.ssh/config to handle the username/host address, key input, ports, and whatnot. –  Shauna May 9 '12 at 18:06
show 2 more comments

I recommend a book (free ebook download)

Pro Git by Scott Chacon

Chapter 4 deals with setting up a Git server.

http://git-scm.com/book/en/Git-on-the-Server

share|improve this answer
1  
+1 Pro-Git is likely the best online resource. –  Marco Ceppi Feb 7 '11 at 14:39
add comment

For all my Git server setups I use Gitolite which allows for a security granularity of "per-branch" access. Setup is pretty straight forward if you're doing it on a remote server it's as easy as running an interactive script. In addition to this "easy-to-setup" nature it also has a package in Natty and Maverick install gitolite

This won't provide a web frontend like Github, or Gitweb - but you can easily configure and install those on top of something like Gitolite.

share|improve this answer
add comment

http://scie.nti.st/2007/11/14/hosting-git-repositories-the-easy-and-secure-way can be slightly modified to suit your purposes...a similar tutorial http://blog.agdunn.net/?p=277.

share|improve this answer
1  
note: I am currently putting together a 0 to done rvm,ree/ruby,rails,git tutorial for development client and development server tutorial. it just draws a lot of online tutorials into one place and modifies them a bit, but it's still a work in progress at the moment. –  hbdgaf Nov 11 '10 at 12:40
    
these tutorials are awesome, but well, they're pretty much complicated. Aren't there any "shorter" tutorials? :) –  Paweł Karpiński Nov 12 '10 at 8:03
    
I haven't seen anything more straightforward...most of the tutorials for gitorious and gitosis don't go through creating a sample project and testing(something I think should be in every tutorial). If I see another tut that's more direct I'll keep this thread in mind –  hbdgaf Nov 12 '10 at 14:30
    
@PawełKarpiński - What's so complicated about them? I've used the Gitosis setup before, and it's actually very easy. –  Shauna May 9 '12 at 18:08
add comment

I like gitolite. The Pro Git book has a section on it but I recommend reading the whole book.

As for your multiple users requirement:

Gitolite allows you to specify permissions not just by repository (like Gitosis does), but also by branch or tag names within each repository. That is, you can specify that certain people (or groups of people) can only push certain “refs” (branches or tags) but not others.

share|improve this answer
1  
the book you've mentioned ROCKS. Thanks! –  Paweł Karpiński Nov 16 '10 at 15:30
add comment

Definitely follow the official documentation: https://help.ubuntu.com/community/Git (section Setting up Git and Project Management)

share|improve this answer
add comment

The solution that worked the best for me, was setting up WebDAV.

  • sudo a2enmod sudo dav_fs

  • sudo a2enmod dav

  • add new file to /etc/apache2/sites-available and name it, for example, git.yourserver.com. Edit it and add following lines:

<VirtualHost *:80>

DocumentRoot /var/www/git.yourserver.com/repos
ServerName git.yourserver.net
Options Indexes FollowSymLinks MultiViews

<Location />
    DAV On
    AuthType Basic
    AuthName "git repos"
    AuthUserFile /var/www/git.yourserver.net/password.dav
    Require valid-user
</Location>

</VirtualHost>

  • create directory /var/www/git.yourserver.com and directory repos inside id
  • sudo chown www-data /var/www/git.yourserver.com/repos
  • sudo htpasswd -c /var/www/git.yourserver.com/password.dav user_login and enter password for user named user_login
  • sudo chown root:www-data /var/www/git.yourserver.com/password.dav
  • sudo chmod 640 /var/www/git.yourserver.com/password.dav

Now, sudo a2ensite git.yourserver.com and sudo service apache2 restart.

  • Enter /var/www/git.yourserver.com/repos and create directory, for example, myrepo.git
  • cd myrepo.git
  • git --bare init
  • git update-server-info

Now, logout from your remote server and go to local directory you want to edit your files in.

git clone http://user_login:user_password@git.yourserver.com/myrepo.git

and you've finished. If you want to send your commited changes to the server:

git push origin master

You can create as many users as you want using sudo htpasswd. Just remember not to use -c switch, when adding more users, because old file will be deleted.

share|improve this answer
3  
HTTP is the "dumb" protocol that is supported but strongly discouraged. The native git protocol works much better, and is easier to set up since all you have to do is have a working ssh server ( which you already should ) and install git-core. No need to muck about with apache at all. –  psusi Apr 16 '11 at 2:44
add comment

It is very easy to achieve with gitolite. In less than an hour you will have easy configurable and secure multiuser git server.

I have an howto article on my site

share|improve this answer
add comment

I also like the gitolite approach for managing users and security. I have a Git + gitolite server AMI for EC2 currently being tested. Feel free to give it a try; documentation is available here:

Alestic Git Server

Using this approach, you can have a central Git server with private repositories running in a matter of minutes. There is a learning curve for gitolite and EC2 if you aren't familiar with them.

share|improve this answer
add comment

here is an example that explain "How do I host a Git repository?" for myself in local using ssh. just need "python-setuptools" and "ssh". hosting-git-repositories-the-easy-and-secure-way

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.