CodeSamplez

Programming and web development blogs

  • Facebook
  • Google+
  • RSS
  • Twitter
  • Home
  • Featured
    • C# Tutorials
      • LinQ Tutorials
      • Facebook C# API Tutorials
    • PHP Tutorials
      • CodeIgniter Tutorials
    • Amazon AWS Tutorials
  • Categories
    • Programming
    • Development
    • Database
    • Web Server
    • Source Control
    • Management
    • Project
  • About
  • Write
  • Contact
Home Web Server How To Connect To Amazon EC2 Instance From Local PC

How To Connect To Amazon EC2 Instance From Local PC

Rana Ahsan January 10, 2013 Leave a Comment


 How To Connect To Amazon EC2 Instance From Local PC    

This article of amazon web service tutorial series , aims to show you step by step how you can connect to amazon EC2 instance remotely right from your PC so that you can manage it in the ways you wish. I hope, you have already know about setting up amazon EC2 Linux instance, and have one ready to be connected. In brief, I will describe about the following three key features here:

  • Amazon EC2 Security Group: You will know what is security group, how important it is and how to configure it properly.
  • Set Up SSH Keys: To connect to instance, a key must need to be set up. If you haven’t already during launch of the EC2 instance, you can learn to do it now also.
  • Connect To Your Amazon EC2 Instance: Two different ways are there and I will show the easiest one to get connected for performing necessary operations on your instance.

Make sure, you have read or know about the earlier tutorials on this series to understand this one flawlessly.

Understanding Amazon EC2 Security Group:

This is a very important aspect for management of your AWS EC2 instances. You need to understand properly what kind of security your server needs and thus configure one or assign a previously configured one. Lets go to the ‘Security Group’ option from the left menu items.
EC2 Security Group Options

As you can see (under ‘inbound’ tab at bottom), you can add as many security group as you want and each can be configured with several protocol/IP access grant. You can either add your own custom port range, or can use the given options for various protocol like SMTP,HTTP, SSH etc. which will automatically open the default ports used for those services. After adding a rule, you must need to submit the ‘Apply Rule Changes’ button as well.

For this tutorial, as we will need to make an ssh connection to our server, please make sure that you have added and applied the ‘ssh’ protocol rule properly.

Adding A Key Pair:

For able to access via ssh, we will need a ssh key pair as well, instead of password based authentication. If you already did one while launching an ec2 instance, you won’t need to do anymore. Just make sure you have the key downloaded on your local PC. But, if you need a new key pair, please go to the ‘Key Pairs’ menu option on left of EC2 dashboard. Click on ‘create key pair’ button.
create key pair

Enter a name on the pop up window and submit. A key pair will be created and available to you for download to your local PC. In an alternative way, you can import an already existing key pair from your PC as well as follows:
import key pair

You need to make sure that the ssh key is in a secure place and have proper private access mode(644 is preferred). Otherwise key will be ignored while connecting and you will be shown an error message mentioning it.

Let’s Connect To Amazon EC2 Instance:

As we are set up with the security configuration and have our ssh key as well, we can now go ahead to connect to our instance. Go to your ‘instances’ menu option. Right click on the instance or check the instance and click on ‘Actions’ button above. From the list of commands, choose ‘connect to instance’ option. after clicking it, you should come up with a window with two different options as follows:

  • From Browser Using Java SSH client: This is the easiest and my personally favorite option. You won’t have to have installed anything on PC, just need to have java enabled on browser. There is a small concern though. You won’t be able to use chrome for this purpose if you are a mac OSX users( as java 7 for mac doesn’t go well with 32 bit chrome).
    Java SSH Client For Connect To Amazon EC2 Instance Window
  • Using A Standalone SSH Client: You can use x-shell/putty in windows environment. For mac or Linux OS, terminal will work fine as well. Though I usually face an issue on mac terminal. It get hanged after some time and I need to restart the terminal and re-connect, which seems annoying to me.
    connect via your own ssh client

As the easiest option, we will see how can we get connected from browser. First, check whether java is enabled on your browser. If not, above connection window will show you a message mentioning that. In this case, run latest java run-time installer and restart browser(if required). After you have enabled java successfully, you should be able to see options to enter in this window:

Public DNS: The public DNS address/IP will be given for the instance you selected. You won’t need to enter this.
User Name: It’s given as ‘root’ by default. However, amazon won’t allow you to connect as root for security reason. Rather, you will rather need to access via another user and then you may switch to root if you want. Here, for my case, a default user ‘ubuntu’ was existed by default and I did entered that username here.
Key name: It’s also given by default with the name you created/imported the key pair.
Private Key Path: The path of the private key file on your local system. Give the full path name. Just to mention, this key doesn’t have any extension.

Also, optionally you can select to save these given info on browser, so that next time you don’t need to re-enter them.

Now, click the ‘Launch SSH Client’ button. If you have done all properly, it should get you a java based ssh terminal as follows:(you may be asked for permission first, from OS as well)
launching java ssh client

Congratulation, you have done it! We are now successfully connected to our amazon ec2 instance via ssh protocol.

Run Basic Linux Commands:

Well, let’s test that we can really run commands on our terminal. first, after logged in, you should be able to see whether there is any update available for OS or not. If so, lets run the following commands to get our OS up to date:

$ sudo apt-get update
$ sudo apt-get upgrade

If it’s done, we can hope (and definitely will 😉 ) to be able to run our other necessary commands also in future then.

Change The Key Pair For EC2 Instance:

Usually, the key pair attached at the time of creation is the only key pair you can access your instance with. If in any case, you loose the ‘.pem’ file you downloaded or deleted the key from aws control panel, you might need to update the instance with this new key pair. It’s not very much easy. An stack-overflow answer to thread on this key pair change issue explains the procedure very well. Follow those instruction to get it done. However, on step 5, if you don’t know how to mount a EBS volume on a ec2 instance, follow this stackexchange thread.

References:

Please checkout amazon’s official documentation about connect to amazon ec2 instance as well for further reference. Feel free to ask any question, if you have. And stay tuned to receive the next tutorial 🙂

Share If Liked

  • Click to share on Facebook (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Pinterest (Opens in new window)
  • Click to share on Reddit (Opens in new window)
  • Click to share on Tumblr (Opens in new window)
  • Click to share on Pocket (Opens in new window)

Filed Under: Web Server Tagged With: aws, cloud server, ssh

About Rana Ahsan

Rana is a passionate software engineer/Technology Enthusiast.
Github: ranacseruet

Leave a Reply Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Email Subscription

Never miss any programming tutorial again.

Popular Tutorials

  • Generate HTTP Requests using c#
  • How To Work With JSON In Node.js / JavaScript
  • PHP HTML5 Video Streaming Tutorial
  • How To Work With C# Serial Port Communication
  • Facebook C# API Tutorials
  • Get Facebook C# Api Access Token
  • Control HTML5 Audio With Jquery
  • How To Work With Multithreaded Programming In C#.NET Application
  • LinQ To SQL Database Update Operations In C#
  • 8 Most Frequently Used And Useful PHP Array Operations
Follow Us On Twitter

Recent Tutorials

  • Document Your REST API Like A Pro
  • Understanding Golang Error Handling
  • Web Application Case Studies You Must Read
  • Getting Started With Golang Unit Testing
  • Getting Started With Big Data Analytics Pipeline
  • NodeJS Tips And Tricks For Beginners
  • Apple Push Notification Backend In NodeJS
  • Web Based Universal Language Translator, Voice/Text Messaging App
  • How To Dockerize A Multi-Container App From Scratch
  • Getting Started With NVML Python API

Recent Comments

  • waail on How To Work With C# Serial Port Communication
  • pakdhetimin on Few Useful Smarty Examples And Tips
  • virender on Getting Started With CodeIgniter URL Routing
  • Mr JiJo on How To Execute Native SQL Query With Doctrine
  • Khalid on How To Work With JSON In Node.js / JavaScript

Archives

Resources

  • CodeSamplez.com Demo

Tags

.net apache api audio aws c# cache cloud server codeigniter deployment doctrine facebook git github golang htaccess html5 http image java javascript linq mysql nodejs oop performance php phpmyadmin plugin process python regular expression scalability server smarty ssh tfs thread tips ubuntu unit-test utility web application wordpress wpf

Copyright © 2010 - 2019 · CodeSamplez.com ·

Copyright © 2019 · Streamline Pro Theme on Genesis Framework · WordPress · Log in