Configuring EC2 authentication

Within AWS, all AMI Linux images are configured to authenticate any SSH session using a key pair authentication system instead of a password.

Before an EC2 instance is to be launched, AWS prompts us to configure an SSH key pair to be able to connect. We can either create our own SSH key pair or use an existing one:

  1. Let's create a new key pair and name it ubuntukey.
  2. Then, download the key pair and launch the instance. The key pair file we get is ubuntukey.pem. The name of the file will change based on the key name that was provided previously. Ensure that the key file is stored securely. In case the key is lost, AWS won't provide another key file and you will no longer be able to access your EC2 instance.
  3. Once the key file has been downloaded, AWS redirects you to the Launch Status page to let you know that your EC2 instance is being launched:

We can now go to our list of EC2 instances and find out the public IP address that has been assigned.

Now, to connect to the AWS machine, you can do so from a local Linux machine:

  • Bring up the Terminal and issue the following command: 
ssh -i <<keyname>>.pem ec2-user@<<your public ip>>

However, connecting from a Windows local machine requires some more work:

  1. Install PuTTY on your local machine. We now have to convert the .pem file in to a .ppk file, since PuTTY only accepts .ppk (PuTTY private key).
  2. Launch PuTTYgen from your start menu and click on load. Select All files:

  1. Now, point PuTTYgen to the .pem file that we have downloaded. PuTTYgen will then load and convert your file:

  1. Once the .pem file has been loaded, click on Save private key to generate the .ppk file. PuTTY displays a warning and asks whether you want to save the key without a passphrase. You may select Yes.
  2. Provide a name for your .ppk file and click Save.
  3. Once we have converted the .pem file in to a .ppk file, we can connect to our EC2 instance using PuTTY. Start by launching PuTTY from the start menu.
  1. In the Host Name field, enter the hostname, ubuntu@<<your public ip>>. Leave the port at 22:

  1. Next, click on the + button next to SSH. Go to Auth and, next to the field named Private key file for authentication, click on Browse. Point PuTTY to the .ppk file we have created:

  1. Lastly, click on Open to start your SSH session:

Since this is the first time that you are logging into the instance, you will receive the following alert.
  1. Click on Yes to continue. You will be authenticated to the Ubuntu instance:

That concludes the exercise for this chapter. We have successfully created an EC2 machine and learned how to create new VPCs and subnets. We have also seen the different types of storage volumes offered by AWS, and learned how we can configure firewall rules for a particular instance. Finally, we set up authentication and logged in to our Ubuntu machine.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.4.239