DEV Community

Cover image for How to connect to a EC2 instance having only private IP using a jump server.
meera123
meera123

Posted on

How to connect to a EC2 instance having only private IP using a jump server.

The following article explains how to connect to an ECS instance using only a private IP address.
The first thing I would like to do is introduce some key terminologies, where we will first try to understand a few things, and then move on to the implementation.

Key terminologies:

  • ec2 instances: EC2 instance is like a computer or laptop where you can run your os like Linux, windows, etc.
  • AMI(Amazon Machine Image): It contains the operating system like windows ,amazonLinux, sushelinux which we use to launch our ec2 instance.
  • vpc(virtual private cloud): vpc is an isolated network within aws where we deploy our resources so that they can communicate with each other.
  • Private IP: Using private IP we can not connect to the internet directly.
  • Public IP: Using public IP we can connect to the internet directly.
  • Key pair: A key pair has a public key and a private key. So basically this is a set of security credentials that we use to prove our identity while connecting to an ec2 instance.
  • Bastion host: The ec2 instance which is having a public IP from which we try to connect to an instance present in a private subnet is called a Bastion host.

EC2 Instance Connect allows you to connect to EC2 instances using three different methods:

  • A browser-based client accessible via the AWS Management Console.
  • Your own key and SSH client.
  • EC2 Instance Connect command line interface (CLI).

In this article we only discuss about connecting ec2 instance using key and SSH client.

Step 1:

  • Start by creating an EC2 instance that has a low configuration. Ensure that this EC2 instance and the instance with the private IP are in the same VPC. And this instance must have a public IP.
  • Connect the instance by giving key pair to SSH client. And connect to the root.
sudo su
cd
Enter fullscreen mode Exit fullscreen mode

Now try to connect to the private EC2 instance. You will notice it is not connecting because the private key pair is not there.

step 2:

  • Now login to vi editors with a file name the same name as the private key pair file. In my case, the key name is example.pem.
vi example.pem
Enter fullscreen mode Exit fullscreen mode

Image description

  • Copy-paste the key into the editor. Save and exit to the editor.

Image description

  • Now give permission to the owner by using the following command.
chmod 600 example.pem
Enter fullscreen mode Exit fullscreen mode

Image description

You are good to go.

Now trying to connect to the ec2 instance having private IP. It will be connected.

Top comments (0)