In order to configure an ssh (or putty) connection to a running Amazon Web Services (AWS) instance, do the following:
1. Note (or write down) the key pair name (you must have the private key (*.pem) downloaded to your local computer) of the instance.
2. Note the public DNS address of the running Amazon instance (ec2-AAA-AA-AA-AAA.compute-1.amazonaws.com)
3. Configure your AWS security group to allow connections on port 22. I use the “default” security group, so I modified it to allow connections on port 22 from any IP. You can limit IP addresses for more security, or you may chose to reconfigure your AMI instance to run the ssh server on the port other than 22.
4. Start the instance using Amazon Web Services (AWS) console.
The next set of steps are done on your local computer (the one used to connect to the remote Amazon instance).
5. Start puttygen.exe.
6. Click on the “Load” button and select the private key file (*.pem). Putty filters for the file extension *.ppk by default, so you will need to set the file filter to *.* to select the file).
7. Once the private key is imported, you will get a confirmation message.
8. Click on the “Save private key” button to convert the Amazon private key (*.pem file format) into the putty format (*.ppk). You will be prompted with the file location to save the file to; save the file and note the location (typically, it is your User directory). You may choose not to use the password phrase for the private key, in which case you will be prompted with a puttgen question to ensure this is what you want. If you choose to use the password, you will have to enter it every time to use the private key to connect to the AMI remote server; personally, I chose not to use it, so that I use password-less authentication based on the private key stored on my local computer.
Configure putty to use the newly created key:
9. Open putty.exe.
10. Under Connection->SSH->Auth->Private key for authentication, select the key generated by puttygen in steps 4-7 (the *.ppk file).
11. Under Session->Host name (or IP address), type the username@public DNS address (from step 2), e.g. ec2-user@ec2-AAA-AA-AA-AAA.compute-1.amazonaws.com. Please note that “ec2-user” is the default user name for many AMI images, but not for all. For instance, the official Ubuntu images use the “ubuntu” user name, so your Host name entry would be ubuntu@ec2-AAA-AA-AA-AAA.compute-1.amazonaws.com.
12. Save the putty session in the “Saved session” list by specifying the name and clicking on the “Save” button under Sessions (for example, “ec2”).
13. Test your connection: in the command prompt, type: “putty ec2-user@ec2-AAA-AA-AA-AAA.compute-1.amazonaws.com” (for official Ubuntu images, the user name is “ubuntu”, e.g. putty ubuntu@ec2-AAA-AA-AA-AAA.compute-1.amazonaws.com”. Verify that the connection is successful.
14. You can also create a shortcut “bat/cmd” Windows file in order to minimize typing required to start the connection. In my case, I created the file “ec2-connect.cmd” with the following line:
putty -load “ec2”
and saved it in my c:\Windows folder.
15. At the command prompt, i can therefore type “ec2-connect” in order to automatically start putty and invoke my profile.