Running an Amazon EC2 Linux Instance

Well if you read my previous tutorial then hopefully you’ll have an understanding of how to setup and run an Amazon EC2 Windows Instance, In this tutorial I’ll go through how to setup a Linux instance, don’t worry I’ll go through it from the start so you don’t need to read my Windows Tutorial if you don’t want.

I used Windows for my first tutorial because nearly everyone has used it at some point. However Windows has many drawbacks, the first and foremost being its Windows and it also takes 15 minutes to start-up. Linux only takes a few minutes to power up, however it does not have a nice GUI like windows, you’ll have to use the fun fun Command line, no seriously its more fun then windows, it doesn’t crash.

So how do you get one of these fast and reliable Linux instances up and running, well….

First you need to log-in to your “AWS Management Console“. If you haven’t done you will need to setup an amazon account, this is pretty easy and Amazon kindly guides you through the process. Once signed in you will get a screen that looks like this:

This is the main interface for controlling your Amazon EC2 account, we can control our instances, AMI’s, Key Pairs, Security Groups but more on that later. We can also change the Region we want to use buy changing the menu in the top left of the screen, however for this tutorial leave it at US east.

Step 2:

After having a look around its time to launch and instance, to do this click the “Launch Instance” button in the middle of the screen:

For this tutorial we are going to use an Ubuntu AMI, this is because I personally prefer Ubuntu and it gives you a chance to see how to run an AMI that is not part of the Amazon “Quick Start Set”. Here we need to search for the AMI, this depends on what region your currently working in, if you are in US-East you will need to search for “ami-2d4aa444", ami codes for different regions can be found at alestic.com. Once you have found the correct AMI click the select button to move to the next step.

Step 3:

The next window is where we choose the hardware settings:

Number Of Instances: Here we can choose how many instances to start, for this tutorial leave at1

Availability Zone: For each region there is several data canters, here is where we choose which one we want, for this tutorial leave to“No Preference”

Instance Type: Here we choose the hardware to use, “Small (m1.small, 1.7GB)” is the cheapest and smallest therefore we will use it for this tutorial.

Click the Continue button for the next step.Step 4:

This window is for more advanced setups therefore we are not going to talk about today, just leave everything to “Use Default” and click continue.

Step 5:

Now we have to set up our new Key Pair. A key pair used so we can securely connect to our instance, we wouldn’t want anyone else playing with our server now would we. A key pair consists of two files one will be on the server itself and we will have the other. To make a new key give your new key a name and click “Create & Download Your Key Pair”. This will open up a download window with a .PEM file, download this file to somewhere safe as you will need it later. If you launch a new instance later you can “Choose from your existing key pairs” so keeping the key file safe will save you time later on.

Step 6:

Once you have downloaded your Key File you should be directed to the next window, here you will setup the firewall rules for the instance. As default for a Linux instance port 22 will be open, this is so we can connect to it via ssh, remember if you are using a Windows instance you need to open port 3389 for RDC. You may also want to use your server for serving things, shock horror, in witch case you will need to add a firewall exception for these services, for example if you want to run a web server you will need to add port 80 or choose HTTP from the drop down box.

Once you have added all the rules you want, give the Security group a name so you can use it again later and click “Continue”. Don’t worry too much about this because you can always adjust the rules once the server is running buy going to the dashboard and selecting Security Groups.

Step 7:

Ahh finally we have can launch our instance. This window is just a summary of all the previous steps, when you’re ready to run your instance click “Launch” and now your instance is all running, rite? Well almost, its a bit pointless if we don’t connect to it. To do this we need make sure the instance is running properly, go back to the AWS Management Console and click “Instances” on the right hand side.

Step 8:

Now you will see this window, this is where you can monitor all your instances, connect to them and terminate them. Now you should see your instance is now running (if it says pending wait a minute or two). First of we want to find the address of our instance, if you click on you instance and scroll down in the bottom window you should find a field called “Public DNS:” note down this address.

Thankfully Ubuntu is much more secure then windows and it allows us to log-in using the key file we downloaded, however this key-file needs to be converted into something PuTTY can read. To do this open PuTTYgen (Can be downloaded from here)

Step 9:

Now click the “Load” button in middle of the window. Choose the location where you saved your key-pairs .pem file in step 6, then press OK, (sometimes you need to change the file type to “All files” to be able to see a .pem file).

Now choose a password that you want to log-in to your instance with and enter it into the “Key Passphrase” box, then click the “Save private key” button and choose a location for you new key. You only need to do this step once so long as you choose the same key when you launch a new instance you can use the .ppk file you just generated to log-in to the instance.

Step 10:

Buy now your instance should be up and running, you can check this on the “AWS Management Console” on the instances section to see if your new instance is running. So now it’s time to log-in to your new instance, open PuTTY (Can be downloaded from here) and enter the Public DNS we noted in step 8 in to the “Host Name” box. Now you’ll need to tell PuTTY where to find the key-file to use for the connection.To do this scroll down to “SSH” on the left hand side of the window and select “Auth” and enter the location of your .ppk file into the “Private key file for authentication” box. Now click the open button at the bottom of the window to start the connect. You may get a message about saving a key, just click the Yes button.

Step 11:

Now enter ubuntu (lower case) as the log-in and enter the password you chose earlier for the password. Now you should be logged into your new Ubuntu instance, simple’s .

Oh yeah, don’t forget to terminate the server when you’re done playing, otherwise amazon will keep charging you, just go back to the “AWS Management Console” then “Instances” and right click on the instance and press “Terminate” this effectively pulls the power from the server and will stop Amazon from charging you anymore.

I know this is a long process but next time you run an instance it will be much quicker as you have done all of the setup, you pretty much click Next, Next, Next, Launch. So Well done and I hope EC2 helps you with your computing needs.

NX Client Ubuntu EC2 Image:

If you have never used Linux Command line then being forced to use it like this might seem a little overwhelming at first, you should try to get on with it you’ll become fluent in no time. But if you do want to use Gnome with your Instance you can: You’ll need to use the AMI: ami-caf615a3 when starting your instance. Then You’ll need to login to your instance, see above, and type:

sudo apt-get update && apt-get upgrade -y
sudo user-setup

and enter some login details. This will be the details you’ll use to login with the NX Client. Now You’ll need to install NX Client on your local computer. For Ubuntu type:

For windows users download and install the latest client from here, Once Install Point the NX Client to the external hostname of your Ubuntu desktop EC2 instance and enter the username/password from above. Choose the “Gnome” desktop.

This entry was posted on July 9, 2010, 3:29 pm and is filed under Tutorial. You can follow any responses to this entry through RSS 2.0.
Responses are currently closed, but you can trackback from your own site.