How to set up a free Linux server on Amazon EC2

I bet you didn’t know that Amazon sell computing time. Well they do. After having to build massive data centres full of web servers to handle the largest book store website in the world, they discovered that they had to have lots of extra computers standing by just to handle Christmas and the new year shopping rush. The logical conclusion? Rent out space on those servers to other people when Amazon don’t need them. That has now expanded massively and Amazon are one of the biggest resellers of virtual private servers. (VPS) A VPS is basically a complete computer contained within another computer. The physical computers can pretend to be many smaller virtual computers, which the customer can have complete control of without affecting anyone else.

The most intriguing part is that Amazon bill for these services in tiny increments, so that if you like, you could rent a massive server with 13 processors and 23GB of memory, but just for ten minutes. Indeed, you can rent an entire supercomputer for a day. The service is called the Elastic Compute Cloud, or EC2 for short. You can also rent a tiny little server with 1 processor and 613MB of RAM. In fact, at the moment, you can have that server completely free for a year! You will only pay if you use extra disk space or more than 15GB of data transfer. The service is really aimed at web servers, but it can also be used to run a game server, and I will show you how. Using Amazon EC2 is quite complex and not for the non technical, but hopefully this guide will get you running.

I will write another article later and tell you how to set up a Source (SRCDS) server for games from Valve such as Team Fortress 2 (TF2) and Half Life 2:Deathmatch. (HL2:DM, HL2MP) For now, here is how to get started with a free Linux server on Amazon EC2. 

Signing up to Amazon EC2

First of all, you will need to get an EC2 account. To get one, you will have to provide a credit/debit card number, and a phone number.

  • Go to http://aws.amazon.com/free/ and click the “Sign up” button.
  • Enter your email address, select “I am a new user” and click the “Sign in” button.
  • Fill in your details and hit “Create Account”
  • Amazon will then ask for a phone number, and call you. This is an automated call – when you answer it, it will ask you to enter the PIN that is displayed on the web page.

Creating a VPS

Once you are signed up and verified, you need to tell Amazon to create your virtual server, or an “Instance”.

  • Sign in to the AWS Management Console. If you have closed it, here’s the link. http://aws.amazon.com/console/
  • Click the “EC2” tab.
  • In the left menu bar, change the region the the one nearest you. I selected “EU West (Ireland)”
  • Click the “Launch Instance” button under “Getting Started”
  • Next you have to select an AMI (Amazon Machine Image) which contains the operating system that you want. For our free Micro server, I recommend “Basic 32-bit Amazon Linux AMI” which should be at the top. Find it and click the “Select” button.
  • In the “Request Instances Wizard” change “Instance Type” to “Micro (t1.micro) (Free Tier Eligible)” This is important, get it wrong and you will be charged per hour! Leave the other settings as they are and click “Continue”.
  • On the next screen, just click “Continue”.
  • When requested to add tags, type a name for your server next to “Name” – I used “Game server” – and click “Continue”.

Creating a key pair

Now the complex part, key pairs. EC2 uses encryption keys instead of passwords, and you have to create a key, part of which will stay at Amazon, and part you will download and use to identify yourself.

  • Think of a name for your key pair – this could just be your name, and enter it in the box.
  • Click “Create and download your Key Pair”
  • Save the file, and remember where you put it!

Creating a Security Group

Next we must create a security group. This is effectively where you set up the firewall for your server. You must configure it to allow gamers to connect to your source server.

  • Set “Group Name” to something meaningful like “Source Server” or “Steve’s web server”
  • Change “Custom TCP rule” to “HTTP” (for a web server) and click “Add Rule”.
  • Repeat for each service that you want. Email is POP3, IMAP and SMTP.

Source servers generally work on UDP port 27015. The UDP part is important, TCP won’t work! For simplicity, I just opened up 27000 to 27100.

  • Change “Custom TCP rule” to “Custom UDP rule”
  • In “Port range” enter “27000 – 27100” (Without the quotes.)
  • Leave “Source” as “0.0.0.0/0” to allow everyone to connect.
  • Click “Add Rule”

When you are done adding services, click “Continue”

Lift off!

We’re ready to go! Check the details, and click “Launch”. Close the next box to go back to the console.

  • To see your server, click “Instances” in the left sidebar.
  • Under “My Instances” you should see a line for your new server and under “Status” it should display a green dot and say “Running”.

Connecting to your server

To connect to your new server you must use Secure Shell (SSH) and the key that you made earlier. We’re going to use the PuTTY secure shell client.

  • Go to http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
  • Scroll down to where it says “A Windows installer for everything except PuTTYtel”
  • Click the link to download. At the moment it says putty-0.60-installer.exe but the version number could change.
  • Click through the PuTTY installer.
  • Start PuTTYGen
  • Click the “Conversions” menu and select “Import Key”
  • Open the key that you downloaded earlier. (I told you to remember where you put it!) It has a .pem extension.
  • Enter a passphrase if you want. This will be the password that you have to type to log in to your server.
  • Click “Save private key” and close PuTTYGen.
  • Open PuTTY.
  • In the left menu find Connection – SSH – Auth
  • Click the “Browse” button on the right next to “Private key file for authentication”
  • Open the key file that you just created – it has a .ppk extension.
  • In the left menu again find Connection – Data
  • Enter “ubuntu” next to “Auto-login username” [UPDATED – this used to be ec2-user]
  • Now click “Session” from the top of the left menu.
  • Go to the AWS console in your browser. Click on the line for your server. Details appear in the lower window.
  • Select and copy the part next to “Public DNS” – something like “ec2-46-137-33-106.eu-west-1.compute.amazonaws.com”
  • Paste this into PuTTY where it says “Host Name”
  • Type a name such as “EC2 server” in where it says “Saved Sessions” and click Save.
  • Click “Open” or double click your saved session from the list.
  • Answer Yes to the security alert – you will only see this again if the IP address changes.
  • If all goes well, PuTTY will connect to your server and you will see a linux prompt!

Finding your server

By default Amazon EC2 servers have a dynamic IP address. If you shut down or restart your server, it will receive a different address. The IP address is shown in the “Public DNS” string that we copied earlier. It is the four numbers after “ec2-” but using dots instead of hyphens. For example, mine is currently “ec2-46-137-33-106.eu-west-1.compute.amazonaws.com” so my IP is 46.137.33.106 (It will change when I reboot so that could belong to anyone now.)

If you would like a permanent IP address you will have to pay a little. You need an “Elastic IP” which will be charged at $0.01 per GB that goes through it.

  • Go to the AWS Management Console
  • Click “Elastic IPs” in the left sidebar
  • Click the “Allocate New Address” button and then “Yes Allocate”
  • A line for your new IP appears in the console. Select it.
  • Click “Associate Address” just above that line.
  • Change “Select and instance” to your server, it will probably be the only option.
  • Click “Yes Associate”
  • You can now connect to you server with the new IP address that you just allocated. You should change the IP in PuTTY and resave the connection too.

Caveats and warnings

If you leave this server running for more than a year, you will be charged per hour for it. The current price in Europe is $0.025 / hour.

If you have an Elastic IP, you will be charged for data that goes through it, or if not used, you will be charged a fee to keep it.

If you transfer more than 15GB, you will be charged at $0.15 / GB (Plus $0.01 / GB for the IP if you have one.)

To cancel this, you must disassociate and release your Elastic IP, terminate your EC2 server and detach and delete your disk volume under “Elastic Block Store” – “Volumes”. If you do not remove all of this, you will eventually be charged.

Keep an eye on the costs by going to the AWS console and clicking “Account” at the top, then “Account Activity” at the left side, or clicking here. It only updates once per day.

Uploading files with SFTP

Your server does not have an FTP server software, but it does have Secure Shell which includes SFTP. You can use Filezilla to upload files.

  • Download Filezilla – go to http://filezilla-project.org/ and click “Download Filezilla Client”
  • Run the installer and click through it.
  • Start Filezilla
  • Click “Edit” – “Settings”
  • Under “Select page” on the left go to “Connection” – “SFTP”
  • Click the “Add keyfile” button.
  • Find and open your key file from earlier. (Ending in .ppk)
  • Click OK to close Settings.
  • Click “File” – “Site Manager” (Or the icon just under the File menu.)
  • Click the “New Site” button.
  • Enter the IP address of your server next to “Host”
  • Change “Server Type” to “SFTP – SSH File Transfer Protocol”
  • Change “Logon Type” to “Interactive”
  • Enter “ubuntu” in “User:”
  • Click the “Connect” button.
  • Tick “Always trust this host” and click OK.

You can now drag and drop files into your server through Filezilla.

Installing server software

At this point you have a live Linux server running at Amazons data centre. You are left with a Linux prompt with a green cursor, sitting there waiting for you to type some commands and turn your server into something useful. You need to install software to make it a web server, email server or game server. Guides for this coming soon on this blog. As I haven’t yet written the guide to install SRCDS, you should start here http://www.srcds.com/ and click “Linux Server” to see instructions.

 

Author: Latentexistence

The world is broken and I can't fix it because I am broken. I can, however, rant about it all and this is where I do that when I can get my thoughts together. Most of the time you'll find my words on Twitter rather than here though. I sometimes write for Where's The Benefit too.

9 thoughts on “How to set up a free Linux server on Amazon EC2”

  1. Fantastic details…..Really Really helped me. I was about to buy datacenter server. Yopu saved my money!!!

  2. Can I have WAR file deployed with its own mysql server and some configurations for directory services on this server? would it be charged?

Leave a Reply