aws ec2 keypair putty geekact

Before learning How to Access AWS EC2 via SSH with Key Pair using PuTTY let us see what you learnt earlier. Previously, you read a guide to install CentOS 5. x or 6. x on Amazon Web Services Elastic Cloud Computing i.e. Ec2. I also wrote about avoiding charges while using Free Tier. Your server is up and running. No issues. So, certainly your next thought is to install on the Webmin interface on Generic Linux AMI and other OS like CentOS. However, before that you need to do one more thing.

In the beginning, anything needs to be installed or done via SSH i.e. Secure Shell. It is a command line interface which you can use to control your server. Don’t worry! The whole tutorial is a copy-paste thing. However, it is always good to learn some commands for unforeseen events. You will need PuTTY client for SSH. It is free and most used client on the internet. Get it here as per your computer OS (not server OS). There are many. Download one which says “Installer” – without PuTTYtel.

Services and virtual servers at AWS doesn’t allow password login. You need a key-pair file which acts as login check. If you have created one during VPS installation on EC2 (as told in this guide) then you are good to go. However, if you have skipped it then it’s a little lengthy as Amazon doesn’t allow changing or allotting keys once an instance is started.  Follow SECTION B first if you don’t have any Key-pair.

SECTION A – If You Already Have A Key Pair:

1. I hope that you are instance is running and you have not deleted that key-pair. I also hope you installed PuTTY from that link. Go to Start Menu on your computer, find PuTTY and Run “PuTTYgen” first.
2. A dialogue box will appear. In Parameters option at the bottom, select  “SSH-2 RSA” and number of bits in generating key shall be “1024”.
3. Now click ‘Load’. Change File type to ‘All Files’ and browse to the location of downloaded Key-pair file. Select it and click open.
4. A box will appear as shown to tell that import was successful.

aws ec2 keypair putty geekact

5. Press Ok. Then select ‘Save Private Key’. A warning will appear for passphrase. Click OK. Select the location and give this new file a name. This is your private key for AWS in PuTTY format.
6. Now close PuTTYgen and from Start Menu, start PuTTY application.
7. Write some name in saved session. I gave it AWS-Micro. Click Save.  It will appear in the list. Click it once from that list. Now, on top of this box there is Host or IP address section. You have to put the IP address of your server. Here you have 2 choices. Use Elastic IP or the long public dns provided by EC2.

7a. EIP is much easier to use and remember and also provides much less issues. However it is important to handle it carefully. You can continue without EIP and assign it later also. However if you are very eager then follow this guide here and then continue to Step 8.

7b. For others who want to wait and assign EIP later when server is all ok; keep reading. You will need to go to AWS EC running instance list. There click your instance and details will give an IP. Copy that whole thing. Look at the screenshot.

aws ip address eip putty

8. Come back to PuTTY and paste this in the IP address box.

aws ec2 in putty geekact

9. Now click on ‘+ of SSH’ present in left sidebar. Then on option and then on Auth.

aws putty key profile

10. There is a browse box. Click browse and navigate it to your Private Key which you generated in Step 5. Click ok to come back to the box.
11. Now, go to Top of the same side bar and click on Session. You will notice everything is same as you left. Press SAVE again. This time you saved your profile with server IP and key which is needed to access it.
12. Select your profile and Click Open. Whoosh.  A warning will appear click “Yes” and you will land to command interface of your server.
13. Use username ‘ec2-user’ for Amazon Generic Linux AMIs (as I am using in current screenshot). For any other OS like CentOS, Debian etc. use ‘root’.
14. SSH will announce that you have logged into your server using ‘imported ssh key’.

amazon ec2 login keypair putty

Done! You can proceed ahead for Wedmin installation on your EC2 CentOS or other Linux server.

SECTION B – Only For Those Who Don’t Have Key-pair:

There are certain ways to change, reassign and create a new key – pair for an instance. I will discuss some of them here.

Method 1:  Terminate Instance and EBS and re-launch new instance with the new key – pair. Follow this guide.

1. This is the easiest method without any headaches.
2. This method is only applicable to the instance which was never used and nothing was installed.
3. This method is most useful for people who forgot to create a key – pair or assign the key-pair on initial setup.
4. Not good for people who wants to change the lost key-pair of running the site.

Method 2: Changing Key-pair by relaunching backup Image of instance: Follow this guide.

1. The method involves taking backup and reassigning while relaunch. This one is also easy.
2. Most suited for people who have lost key-pair or want to change the key-pair for a running server and website.
3. It has dangers of losing data if not done correctly.
4. Successful most of the time.

Method 3: Actually changing key-pair in running instance. Follow this guide (In writing).

1. Toughest method of all.
2. There is danger of getting locked out totally even with a current working key-pair.
3. May not be successful most of the time.
So,  when you are done with getting back your key-pair then just follow the SECTION A and get into your server.

Next destination is installing Webmin on AWS EC2

By Mrinal Buddekar

Data Manager and a technology enthusiast! Mrinal Buddekar is Pune based blogger who loves building server, websites, technology, and affiliate blogging.

Hey there!

Help us reach out to awesome people lie you out there. We publish Tech and WordPress, Deals, and Reviews. WE DON'T SPAM!

Your Information will never be shared with any third party