Setup git server with Amazon EC2


We can setup git server on amazon ec2 intances using gitolite. Here is step to do:

1. Configure SSH config
Create new file “~/.ssh/config” which contains your amazon EC2 hostname, user and PEM key location.

1
2
3
4
Host amazon
Hostname 23.21.1xx.xxx
User root
IdentityFile /home/yodi/my-ec2-micro.pem

With this configuration, we can login into EC2 instance with : “ssh amazon”

2. Copy our SSH public keys into Amazon EC2

1
2
3
ssh-keygen -t rsa
cp ~/.ssh/id_rsa.pub /tmp/local.pub
rsync -avr /tmp/local.pub -e "ssh -i /home/yodi/my-ec2-micro.pem" root@23.21.1xx.xxx:/tmp/local.pub

3. Login into EC2 and setup gitolite
Install gitolite :

1
sudo apt-get install git gitolite git-daemon-run

Create new git account for gitolite:

1
2
3
4
5
sudo adduser –system –shell /bin/bash –gecos ‘git version control’ –group –disabled-password –home /home/git git
su git
cd /home/git
echo "PATH=$HOME/bin:$PATH" > .bashrc
gl-setup /tmp/local.pub

Back to your local machine and clone admin gitolite repo:

1
git clone git@amazon:gitolite-admin.git

Voila! now we can start add new repository! 🙂

Create new repository by editing “gitolite-admin/conf/gitolite.conf”, eg :

1
2
3
4
5
repo gitolite-admin
RW+ = @all

repo insurances
RW+ = @all

Then you can try to commit this repo :

1
2
git commit -am ‘create new repo’
git push origin master

Then you can clone new repo by :

1
git clone git@:insurances

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.