You now have a server instance running on EC2. It is time to connect and take it for a spin. Ssh is a UNIX tool for connecting to servers. If you are on a Mac or Linux machine, then you already have ssh installed. We will look at them first, and then explore using the similar putty application on Windows.
Before you begin, locate your key file that was downloaded during setup. This is a file with a .pem extension. For these steps, I will assume a file name of myKey.pem. You also need to know the IP address of your instance or the elastic IP you assigned to it.
Opening the Required Port to Connect
You also need to ensure the ssh port is open on your server.
- Log in to the AWS Management Console
- Go to the EC2 Dashboard
- Click on the instances menu. Now, select the instance you want to work with
- In the Description tab at the bottom of the page, find the Security groups item. Click on the group name
- You will see the security group screen. Now, select the Inbound tab at the bottom of the page.
- Click on the edit button
- Select “Add Rule”
- Select SSH from the drop down. Verify the port is 22, and the protocol is TCP. Enter your local address for the tightest security. Otherwise, leave it open to all. It can be secured at a later time. More information about this is provided in the “Further Reading” section below
- The file must have read only access so issue the command:
chmod 400 myKey.pem
- Now use the file to connect :
ssh -i myKey.pem [email protected]
- The IP address can be used, if you prefer
ssh -i [email protected]
- You will be presented with the instance console like this:
Last login: Mon Jun 20 15:07:44 2016 from c-69-137-134-29.hsd1.tn.comcast.net __| __|_ ) _| ( / Amazon Linux AMI ___|\___|___| https://aws.amazon.com/amazon-linux-ami/2016.03-release-notes/ [ec2-user@ip-10-148-76-186 ~]$
Create a private key that Filezilla can use.
- Download Putty from the putty page: http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html. You will need putty.exe and puttygen.exe (if the link does not work you can always do a search for “putty download” and it should be towards the top of the list.
- Run puttygen.exe
- In the type of key parameters select SSH-2 RSA
- Click Load, you will have to change the dropdown to All Files (*.*) in order to find your .pem file
- Browse to your file and select it, click open and click ok
- Click Save private key, Click yes to save without a passphrase.
- Save to a name and the file will be created with a .ppk extension
Now we can connect to our server…
- Open the Putty application (double-click the icon)
- Enter the IP address of your instance in the hostname field but precede it with “ec2-user@”. For example, [email protected] for an IP address of 188.8.131.528
- Click on the plus by SSH on the menu and then click on Auth
- Select browse. Now find the .ppk file you just created.
- Click on Session
- Enter a name in the saved sessions text. Then, click on the save button
- Now when you open putty the next time you can select the session name to load all of this information
- Click on Open
- You will see a command line window open and are now connected to your instance.
Get the Latest Security Updates
If you have not logged in recently or this is your first time you might see a notice to run the update. This will help keep your server running the latest system software. Go ahead and type
sudo yum update
to get the latest updates and install them. Just type y when it asks if you want to continue. This is similar to the Microsoft Windows update feature (if you are familiar with it). Updates to applications on the server are regularly updated to ensure your server is safe and secure.
There is a lot of power that putty and ssh have that have not been covered here. These first books are a great source of details about these tools and navigating the complex aspects of security and connecting to your servers.
You can also check out a good SSH Tutorial at https://support.suso.com/supki/SSH_Tutorial_for_Linux