We have already launched a free instance of an Amazon AMI in our last post. Now we’ll look at the ways you’ll connect to your Linux instance. This will be a lengthy post, mainly due to the fact that there will be a lot of “showing” along the way.
Connecting to a Linux AMI – Securely
SSH Key Pairs
In the last post I didn’t go into how to create a key pair. You’ll need one in order to connect to any instance, so we’ll quickly create one now while we spin up a new Linux instance (just as we did in our last post). Be sure to select one of the available free instances. For this post we will again use the Amazon AMI. When you select the instance you will be spinning up, you can create a new key pair as shown below.
All you need to do is name your key pair, and then you’ll be able to download it by clicking the download button.
Remember where you save your file (it will have a “pem” extension). So in the example above you will download GettingConnectedLinux.pem to your local computer. Don’t share this file with anyone or post it on the net anywhere. It’s your security key into your environment. If you make it public, your environment is now public… so keep it safe. Amazon describes your key pair as follows:
Public AMI instances have no password, and you need a public/private key pair to log in to them. The public key half of this pair is embedded in your instance, allowing you to use the private key to log in securely without a password. After you create your own AMIs, you can choose other mechanisms to securely log in to your new instances.
So now you have a key associated to an instance that you have spun up. Now we can work on getting connected.
Connecting to your instance
Confirm your instance is up and running. Navigate to your Instances menu so we can see what instances are running
You should now see your running instance. In our example we called our Amazon AMI “GettingConnectedLinux”.
Now right-click on your running instance and you will get a sub menu. We are looking for “Connect” at the top of that sub menu.
You’ll get a new dialog that will open. We will be connecting from our browser using the Java SSH client. You can set up your own connection using your own SSH client, but for this example we’ll be using the Java SSH client.
Here’s where we need that key pair file. There is no browse option here… you need to type in the exact path & file name of your key pair file.
When the path and file name are complete you can click “Launch SSH Client”. This will begin the process of connecting to your instance. You will be prompted to add this host to your known hosts if you like. It’s not required. If all goes well, you’ll see a terminal window that is now connected to your instance.
If you know your way around Linux…. you’re all set. You are connected and able to do whatever you like to this instance. You can install packages, configure it as a web server, do anything you like to it. Just remember though, Amazon is tracking the usage. You get 750 hours a month of free usage if you are using a free tier eligible AMI. If you get crazy and spin up 2-3 free tier AMI’s you are chewing up an hour of time for each instance. If you go over the 750 hours you will be charged. So, while you’re playing, keep it to one running instance at a time.
When you are done having fun you’ll want to disconnect from your instance. If you are completely done with your instance, you may want to permanently terminate it. To do this, first disconnect from your instance. Simply select the File menu, then Exit.
If you are going to connect again later, you can keep your instance running. If you want to keep the state of your instance, but don’t want it running any longer, you can stop your instance. If you are done with this instance and want to permanently delete it, you can terminate it. To terminate your instance you can right-click on your instance (as we did when we connected to it) and select terminate.
Remember, this is a permanent action. If you have work you want saved, select “Stop”, not “Terminate”. Once you have you have terminated your instance, you’ll see that reflected in the status of your instance view.
This status will stay in your view for a while, but will eventually be cleared from your dashboard completely.
So now you know how to connect to a Linux free micro instance on Amazon Web Services. Here’s the thing to keep in mind… these are sandboxes for you. You can create, destroy, terminate anything you want as many times as you want so you can learn what you want to learn when you want to learn it. With the micro instances you have 750 hours of free usage per month for one year. Make the most of that year. Experiment, create, try, fail, try again… and come out the other side knowing more than you did when you went in.
Best of luck and let me know if you have any questions!
PS – I have already terminated all the instances that have been used in this post. That’s why I haven’t obscured anything in the images. You get to see what I saw when I spun them up so you get a feel for what you expect to see… but don’t waste your time trying to hack into any of these instances… they’re gone… long gone.