Authorization for SSH Connection

1. Open the Amazon EC2 console at
2. Click Instances in the Navigation pane. Select your instance and look at the Description tab; the Security Groups field lists the security groups that are associated with the instance. Click the view rules link to display a list of the rules that are in effect for the instance.
3. Click Security Groups in the Navigation pane. Select one of the EC2 security groups associated with your instance.
4. From the Create a new rule list on the Inbound tab, select SSH.

5. In the Source field, specify your local system’s public IP address in CIDR notation. For example, if your IP address is, enter
6. Click Add Rule.An asterisk appears on the Inbound tab, indicating that the rule hasn’t been applied.
7. When you’re finished adding rules, click Apply Rule Changes.The new rules are applied to all instances that are associated with the security group.

Connect to AWS EC2 Instance via SSH

If you have to connect to your AWS EC2 instance, you can do it via SSH or Putty, for Windows user.
• Keypair created and assigned to your EC2 instance.
• Keypair locally available for conncection.

If the preconditions are met, then you can start connecting to your EC2 instance.
First, find your Public DNS adress in your EC2 Console.

Now you have 3 ways how you can connect to your instance. Via SSH from Mac or Linux OS, SSH via Putty on Windows or trough the AWS Web.
• For Mac or Linux users, type following in your Terminal.

1 ssh -i .pem ec2-user@PrivateDNSOFYourEC2Instance
• For Windows Users
• Download Putty @
• Do not forget to convert the Pem file to private PKK file with PuttyGEN. Also available on the above site
• Add the Key to the Settings and add your Server into the correct field. You can also save the Settings to a Session. I Recommend it

• Via the WEB. Go to your EC2 Console – > Instance and right click on it. Press Connect and Tada:)

How to set up your own private Git server on Linux
Update 2: as pointed out by Tim Huegdon, several comments on a Hacker News thread pointing here, and the excellent Pro Git book, Gitolite seems to be a better solution for multi-user hosted Git than Gitosis. I particularly like the branch–level permissions aspect, and what that means for business teams. I’ve left the original article intact.
Update: the ever–vigilant Mike West has pointed out that my instructions for permissions andgit checkout were slightly askew. These errors have been rectified.
One of the things I’m attempting to achieve this year is simplifying my life somewhat. Given how much of my life revolves around technology, a large part of this will be consolidating the various services I consume (and often pay for). The mention of payment is important, as up until now I’ve been paying the awesome GitHub for their basic plan.
I don’t have many private repositories with them, and all of them are strictly private code (this blog; Amanda’s blog templates and styles; and some other bits) which don’t require collaborators. For this reason, paying money to GitHub (awesome though they may be) seemed wasteful.
So I decided to move all my private repositories to my own server. This is how I did it.
Set up the server
These instructions were performed on a Debian 5 “Lenny” box, so assume them to be the same on Ubuntu. Substitute the package installation commands as required if you’re on an alternative distribution.
First, if you haven’t done so already, add your public key to the server:
ssh mkdir .ssh
scp ~/.ssh/
Now we can SSH into our server and install Git:
sudo apt-get update
sudo apt-get install git-core
…and that’s it.
Adding a user
If you intend to share these repositories with any collaborators, at this point you’ll either:
• Want to install something like Gitosis (outside the scope of this article, but this is a good, if old, tutorial); or
• Add a “shared” Git user.
We’ll be following the latter option. So, add a Git user:
sudo adduser git
Now you’ll need to add your public key to the Git user’s authorized_keys:
sudo mkdir /home/git/.ssh
sudo cp ~/.ssh/authorized_keys /home/git/.ssh/
sudo chown -R git:git /home/git/.ssh
sudo chmod 700 !$
sudo chmod 600 /home/git/.ssh/*
Now you’ll be able to authenticate as the Git user via SSH. Test it out:
Add your repositories
If you were to not share the repositories, and just wanted to access them for yourself (like I did, since I have no collaborators), you’d do the following as yourself. Otherwise, do it as the Git user we added above.
If using the Git user, log in as them:
login git
Now we can create our repositories:
mkdir myrepo.git
cd !$
git –bare init
The last steps creates an empty repository. We’re assuming you already have a local repository that you just want to push to a remote server.
Repeat that last step for each remote Git repository you want.
Log out of the server as the remaining operations will be completed on your local machine.
Configure your development machine
First, we add the remotes to your local machine. If you’ve already defined a remote named origin(for example, if you followed GitHub’s instructions), you’ll want to delete the remote first:
git remote rm origin
Now we can add our new remote:
git remote add origin
git push origin master
And that’s it. You’ll probably also want to make sure you add a default merge and remote:
git config branch.master.remote origin && git config branch.master.merge refs/heads/master
And that’s all. Now you can push/pull from origin as much as you like, and it’ll be stored remotely on your own remote repository.
Bonus points: Make SSH more secure
This has been extensively covered by the excellent Slicehost tutorial, but just to recap:
Edit the SSH config:
sudo vi /etc/ssh/sshd_config
And change the following values:
Port 2207

PermitRootLogin no

AllowUsers myuser git

PasswordAuthentication no
Where 2207 is a port of your choosing. Make sure to add this so your Git remote:
git remote add origin ssh://

How to Install Git on Ubuntu 12.04
What the Red Means
The lines that the user needs to enter or customize will be in red in this tutorial!

The rest should mostly be copy-and-pastable.
About Git
Git is a distributed version control system released to the public in 2005. The program allows for non-linear development of projects, and can handle large amounts of data effectively by storing it on the local server.

This tutorial will cover two ways to install Git.

How to Install Git with Apt-Get
Installing Git with apt-get is a quick and easy process. The program installs on the virtual private server with one command:
sudo apt-get install git-core

After it finishes downloading, you will have Git installed and ready to use.

How to Install Git from Source
If you are eager to download the most recent version of Git, it is generally a good idea to install it from the source.

Quickly run apt-get update to make sure that you download the most recent packages to your VPS.
sudo apt-get update

Prior to installing Git itself, download all of the required dependancies:
sudo apt-get install libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev build-essential

Once they are installed, you can download the latest version of Git from the google code page.

After it downloads, untar the file and switch into that directory:
tar -zxf git-
cd git-

If you want to do a global install, install it once as yourself and once as root, using the sudo prefix:
make prefix=/usr/local all
sudo make prefix=/usr/local install

If you need to update Git in the future, you can use Git itself to do it.
git clone git://

How to Setup Git
After Git is installed, whether from apt-get or from the source, you need to copy your username and email in the gitconfig file. You can access this file at ~/.gitconfig.

Opening it following a fresh Git install would reveal a completely blank page:
sudo nano ~/.gitconfig

You can use the follow commands to add in the required information.
git config –global “NewUser”
git config –global

You can see all of your settings with this command:
git config –list

If you avoid putting in your username and email, git will later attempt to fill it in for you, and you may end up with a message like this:
[master 0d9d21d] initial project version
Committer: root
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:

git config –global “Your Name”
git config –global

After doing this, you may fix the identity used for this commit with:

git commit –amend –reset-author

How to Install Ruby on Rails on Ubuntu 12.04 LTS (Precise Pangolin) with RVM
About Ruby on Rails
Ruby on Rails is an application stack that provides developers with a framework to quickly create a variety of web applications.

Ruby on Rails does take a little while to install on a virtual server, but luckily there are a lot of helpful tools to make this process as easy as possible.

You can run this tutorial on your droplet as a user with sudo privileges. You can check out how to set that up here: Ubuntu Server Setup

Step One— Install Ruby with RVM
Before we do anything else, we should run a quick update to make sure that all of the packages we download to our VPS are up to date:
sudo apt-get update

Once that’s done, we can start installing RVM, Ruby Version Manager. This is a great program that lets you use several versions of Ruby on one server; however, in this case, we will just use it to install the latest version of Ruby on the droplet.

If you do not have curl on your system, you can start by installing it:
sudo apt-get install curl

To install RVM, open terminal and type in this command:
\curl -L | bash -s stable

After it is done installing, load RVM. You may first need to exit out of your shell session and start up a new one.
source ~/.rvm/scripts/rvm

In order to work, RVM has some of its own dependancies that need to be installed. You can see what these are:
rvm requirements

In the text that RVM shows you, look for this paragraph.
Additional Dependencies:
# For ruby:
apt-get –no-install-recommends install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev libgdbm-dev ncurses-dev automake libtool bison subversion pkg-config libffi-dev

Just follow the instructions to get your system up to date with all of the required dependancies.
sudo apt-get –no-install-recommends install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev libgdbm-dev ncurses-dev automake libtool bison subversion pkg-config libffi-dev

On occasion the zlib package may be reported as missing. The RVM page describes the issue and the solution in greater detail here.

Step Two—Install Ruby
Once you are using RVM, installing Ruby is easy.
rvm install 1.9.3

Ruby is now installed. However, since we accessed it through a program that has a variety of Ruby versions, we need to tell the system to use 1.9.3 by default.
rvm use 1.9.3 –default

Step Three—Install RubyGems
The next step makes sure that we have all the required components of Ruby on Rails. We can continue to use RVM to install gems; type this line into terminal.
rvm rubygems current

Step Four—Install Rails
Once everything is set up, it is time to install Rails.

To start, open terminal and type in:
gem install rails

This process may take a while, be patient with it. Once it finishes you will have Ruby on Rails installed on your droplet.

How to install and configure Git to manage source code
Written on May 2nd, 2010 at 22:55 pm by chia

Git is an open source, distributed version control system with the emphasis on being fast. It was developed by Linus Torvalds for managing Linux Kernel. It was primarily focused for Linux, but now its available for almost every operating system. Its fast on POSIX-based systems such as Linux. Its different from SVN because it creates a private repository on remote server as well. Some projects using Git – Linux kernel, YUI, Fedora, Debian,, VLC, Perl, there is some work going on to shift Drupal on Git too.
Installing GIT on Fedora and Ubuntu
Lets start by installing Git and Gitweb, a web interface for Git.
[root]# yum install git-core gitweb #For Fedora/RedHat based Distros
[chia]$ sudo apt-get install git-core gitweb #For Debian or Ubuntu based distros
Configure Git
First thing you want to do is set up you username and email address. GIT uses colour to notify user about the crucial things so we need to activate colors as well. The following commands will do that for you.
[chia]$ git config –global “Tushar Mahajan”
[chia]$ git config –global “”
[chia]$ git config –global color.status auto
[chia]$ git config –global color.branch auto
Using –global will apply it at global level. It will store the information at .gitconfig in your home directory.
[chia]$ cat ~/.gitconfig
You can check the values by using:
[chia]$ git config
Now we are all set up, we need to create a Git repository.
[chia]$ mkdir project
[chia]$ cd project
[chia]$ git init
Initialized empty Git repository in /path/to/project/.git/
Now you can see there is a .git directory inside the project.
Add some description to the project:
[chia]$ echo “Short Project Description ” > .git/description
Git stores its actual compressed objects in .git/object directory.
It will be empty at this point of time.
[chia]$ git add . # git add is used to add file contents to the index.
# To check what is there in the index files run
[chia]$ git ls-files
[chia]$ git ls-files –stage # this will display all the sha checksums of the indexed files.
[chia]$ git status
[chia]$ git commit
“git status” will show a list of all the new and updated files that are there in the directory.
Add all the files to the repository by using “git commit”. Now running “git status” will show
# On branch master
nothing to commit(working directory clean)
To show the latest commit messages:
[chia]$ git log
Cloning GIT directory
You can clone git directory using either git protocol or using http. Git works on port 9418.
# Clone using git protocol
[chia]$ git clone git://
# Clone using http protocol
[chia]$ git clone
# Git protocol is more efficient for cloning. But in the end you will get same thing.
Now, we have successfully installed and configured Git on our system.

Install (Set Up) Git and Gitosis on Ubuntu
Git is a free distribution revision control initially created by Linus Torvalds for the Linux kernel development. Git is different from subversion in several was, a good solid reference for explanation can be found from a 2008 RailsConf talk on Git by Scott Chacon: (Link).
I will be using Gitosis for this setup, Gitosis is a tool written for Git that helps in the setup of secure access controlled repositories. It will manage multiple repositories under one user account on the host machine. Using SSH keys to identify users, your repositories will be securely accessed and controlled. One large advantage to Gitosis is that your users will not need shell accounts on the machine to access repositories, they will however speak to a singular account what will not allow arbitrary commands.
Git is very local in nature, with remote distributed features. One major thing to wrap your head around is that git resides on your machine and tracks files locally, so if you create a new file and want git to track that file you need to let git know through the add command. Git also has remote locations that give it the ability to push to a, you guessed it…, remote location. You can add many remotes, typically you will see the “origin” remote location in most projects, we will be using origin in this article.
Before you start with this, note that I will try to explain every step as best possible. Some of the other guides out there will lead you along without the explanation, do yourself a favor and avoid the temptation to try and do this quickly… understand as much of git as possible, it will save you time down the road.
Install Gitosis
first install git so that you can pull down gitosis, then navigate to your home and do the clone:
sudo apt-get install git-core
cd ~/
git clone git://
This will create a gitosis folder in your home directory, now to follow convention move the gitosis folder to the /usr/local:
sudo mv gitosis/ /usr/local
Now you need to navigate into the gitosis folder, install python, and run the file to complete the install:
cd /usr/local/gitosis
sudo apt-get install python-setuptools
sudo python install
Now we will create the git user, I specified its home directory to be /var/git so that the repositories are located where my other common files are (apache, mysql, etc):
sudo adduser
–shell /bin/sh
–gecos ‘git version control’
–home /var/git
Now, since we are setting up access for just ourselves at first we need a public key from our machine. You should already be using key access for ssh, but if your not please head over to my ssh article and follow the steps to generate yourself a key. This key is for the client to access the server, some of the articles on setting this up are a little ambiguous about why the key needs to exist, for beginners this can be confusing. You need to upload your clients new file (which is probably named to the server, put it some place like the /tmp directory.
Run this command to add your public key to the gitosis-admin project, that way you can check it out and configure git:
sudo -H -u git gitosis-init < /tmp/
Now for good measure, make sure the post-update hook is set to executable. This sometimes doesnt get set up correctly with older versions of the setuptools:
sudo chmod u+x /var/git/repositories/gitosis-admin.git/hooks/post-update
Now for configuring Git, and getting clients connected.
Git on the Client
Make sure you have git installed on your client:
sudo apt-get install git-core
Now navigate to a folder where you will be checking out all of your repositories, and check out the gitosis-admin project:
cd /media/ARRAY/Dev
git clone git@:gitosis-admin.git
cd gitosis-admin
The repository you just cloned contains all of the files needed to create repositories for your own projects. This project is also the gitosis configuration. You can modify how gitosis works by checking out this project, making changes then pushing it back to the server.
Adding Users
Users will all be using the git account (this is how gitosis works) to access your repositories. You need to add their public keys to the gitosis-admin project and modify the gitosis.conf. So collect the public keys from your contributors and place them in the gitosis-admin/keydir directory, then open up your gitosis.conf and modify it to add your new users.
When I started out I had access for a single user: storrgie@COLOSSUS, now I need to add my laptop… which is storrgie@ENYO and I also want to add a new group for my friends as we are working on a new project. Below shows you where I have added the new users and groups, compare this file with the default gitosis.conf file to see what I have changed:
[group gitosis-admin]
writable = gitosis-admin web.andrewdunn
members = storrgie@COLOSSUS storrgie@ENYO
[group opensourcesoldiers]
members = storrgie@ENYO mka@samsara mrcakes@mrlaptop milman@rorlf
Now I dont have any repos for my friends to work on, so I have not set up the writable field for them. Now for this configuration gitosis will look in the keydir to find matching .pub key files for each of those names.
Lets add the files we want to commit:
git add keyfiles/
git add gitosis.conf
git commit
git push
Now my friends have access to my server, but I need to set up a repository for them to work on. I’ll show you how I added my personal website as a repository instead though.
Creating New Repositories
To create a new repository we must first add some information to the gitosis-admin project. You already have the projected checked out locally so you can make your changes and push Below shows you where I have added my website as a git project, compare this file with the default gitosis.conf file to see what I have changed:
[group gitosis-admin]
writable = gitosis-admin web.andrewdunn
members = storrgie@COLOSSUS storrgie@ENYO
[repo web.andrewdunn]
gitweb = no
description = Andrew Dunn website
owner = Andrew Dunn
daemon = no
So I have added a repo, with a name. I have specified that there is no gitweb access and no daemon access. The description and owner fields are used by gitweb, I have included them in case I want to enable gitweb at a later point. Notice also that I have added web.andrewdunn to the writable list under gitosis-admin.
Now that we have changed the gitosis.conf file lets go ahead and push it up to the repository. You need to add the file to the changes you want to commit, then do a commit to get everything ready, then perform a push:
git add gitosis.conf
git commit
git push
Notice the git add, you have to let git know what changes you are adding to the commit. If you are lazy like me, you can just do a “git add .” and it will add all the changes from the tracked files. If youcreate a new file, you have to do a git add to let git know its tracking that file.
Now lets go to the folder you want to push as a repository and get everything straitened out there. You will need to first initialize the folder as a git repository, then add the files you want git to track. In this case I am going to to add all of the files, you can track individual files if you want to add them individually.
cd web.andrewdunn
git init
git add .
git remote add origin git@:web.andrewdunn.git
Now we have done several things, we have initialzed the project and added all the files in the web.andrewdunn directory to be tracked. We have also added a remote location named origin, you can check these by running the “git remote show” command.
Now we want to commit and push the project, and specify that this is the master for the repository:
git commit
git push origin master
Now you should see the project get compressed and pushed to your remote source control server.
Public Access
So if you are running a public project, you have users who are key authenticated to commit to your project but need anonymous clone access, git-daemon will handle the need. Git-daemon comes with git itself, not with gitosis. Go inside each of the repositories that you want to give public access to and create a new file:
cd publicproject
touch git-daemon-export-ok
sudo -u git daemon –detach –verbose –base-path=/var/git/repositories
Alternatively you can export all of your projects with this command:
sudo -u git git-daemon –base-path=/var/git/repositories/ –export-all
Non-standard SSH port access
If you are running your ssh daemon on a non-standard port, using the syntax: git@::repository.git will cause problems. To avoid this you need to add a host to your /etc/ssh/ssh_config file:
Port IdentityFile ~/.ssh/id_rsa
Protocol 2
I initially struggled with this setup, however after learning a little more by trolling their IRC and reading some of their documentaiton git turned out to be very interesting. Expect this setup to take a couple minutes, its not going to be like a deploy-able deb file or something you install from the repositories with minimal configuration effort. The time it really takes to get gitosis running is rather slim once you understand what your doing.
Good luck with your projects!

Deploy Rails application to Apache + Passenger on Amazon EC2
I recently deployed a rails application to Amazon EC2. Here are some of notes which maybe helpful to others doing similar tasks.

Assume ruby and rails are already installed in your amazon EC2 instance, below is the steps to deploy your rails application to Apache:

1. Install Apache
sudo -s
yum install httpd
yum install httpd-devel

2. Install Passenger:
gem install passenger

3. Configure Passenger with apache:
rvmsudo passenger-install-apache2-module
(then follow the steps as indicated in the command line window)

4. Deploy your application to the server and change the configuration file to point to the correct direction. (/etc/httpd/conf/httpd.conf)
(Important Note: if you are trying to deploy a development version of your application, you must specify RailsEnv as development in your Apache configuration)

Below is an example of the Apache configuration:
DocumentRoot /home/ec2-user/your_rails_app/public
RailsEnv development

Allow from all
Options -MultiViews

Leave a comment

Leave your opinion

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: