Instances within the same VPC can connect via their private IP addresses, as such, it is possible to Access Private Subnet EC2 from an instance in a public subnet. So, Amazon instances use SSH keys for authentication.
- Log in to the AWS console.
- Go to services select EC2
- Go to create an instance
- Select Amazon Linux2 AMI SSD Volume type.
- Select general purpose
- Which has t2.micro and select next configure instance details.
- Now we have to go configure details.
- Select the subnet as default us east 1b.
- Select the Auto-assign subnet public IP as “use subnet setting enable).
- And click next to add storage.
Let the added storage be the default one which has volume type root and then click next.
Give the key as name and value as suggest cloud private for private key and public for the public key. Then click next to configure security group.
Select SSH off port 22, HTTP of port 443, HTTP of port 80.
Review the instance and click on launch.
So after clicking the launch it shows a popup.
After choosing the key which we have already created.
Similarly, create another instance with public subnet. I have given privately for us east(1a), and (1b) as a public subnet. Below is for the public where we have to disable the auto-assign type.
Below are the two instances created private and public. If we click we can it shows whether we have a private subnet or public subnet.
Now open putty and paste the public IP address. In the hostname or IP address. Go to SSH.
And select the private key you have chosen. Then click open.
Step 15: Window appears asks login user then type ec2-user.
paste the pem file it shows that the ec2 machine has been connected from a private subnet using SSH.
Amazon instances use SSH agent authentication. As we need private keys while connecting to the private instance similarly the public instance requires a private key on your host machine. There is an alternative solution is to use SSH which allows users to connect the host to another instance without storing the private key on the computer. Access Private Subnet EC2 and let us know incase of any issue.