I am trying to ssh using the IP address to connect the VPC in a region / across region. using the ssh -i ec2-user.pem ec2-user@ command provided and not working. please advise on what is going wrong. tried 3x. should i be using the private or public ip. pls walk me through the lab and credential set up
Not sure which course you’re referring to (including a link to the lab is very helpful for that), but in general, when you create an EC2 instance, you either have to supply a keypair to use, or you have AWS create one for you and you download the PEM key. You should use the public IP address if you’re contacting the EC2 instance “from the outside”., using a command like
ssh -i ec2-user.pem ec2-user@PUBLIC-IP-ADDRESS
The pem file will need to have a fairly secure access set up (Linux chmod 400 ec2-user.pem
is good) for this to work correctly.
I did specify the course, the AWS Networking Fundamentals. Lab - Connecting 3 VPCs in a Region & Cross Region - Part 1 & II. Possible to provide the solution on how to solve. As per instructions:
You’ve set up 2 Instances, each in a separate VPC.
Goal - to access the 2nd Instance - named ec2-vpc-2, using its Private IP Address without using the Public internet.
To access the 1st Instance - execute the following command from your lab machine:
ssh -i ec2-user.pem ec2-user@<public-IP-of-ec2-vpc-1>
After successfully logging in to the ec2-vpc-1 Instance
Proceed to access the 2nd Instance - ec2-vpc-2, using its Private IP address:
ssh -i ec2-user.pem ec2-user@
You can copy the .pem key file to the ec2-vpc-1 Instance using the following command:
scp -i ec2-user.pem ec2-user.pem ec2-user@:~/
Tried the above, does not work. Used both the Private and then the Public IP. when checking answer - lab showing not correct.
It never hurts to add the lab link, BTW – but thanks for clarifying.
I just worked my way through the lab. The first time you try to access instance 2 from instance 1, it fails because there is no route to host. So initially, you can only get to instance 2 using the public IP.
The rest of the lab will show you how to create a peering connection between the two subnets, which will allow you to use the private IP to access instance 2 from instance 1 using the private IP.