SSH into Public Instance4:15
Public instances also get a public DNS hostname, and a private DNS hostname. Now that the instances are created and ready, let's see how we may communicate with the instances, how we may communicate between the instances, and how the instances may communicate with each other, with the public internet. So get ready for some terminal work. Let's head over to the terminal, and ssh into the public instance. So ssh -i laracastec2.pem user@public_ip_address, then open to, add, and we go grab the public instance public IP address, copy it, paste it in the terminal, and execute the command. And here we go, we are connected to the public instance.
Prepare Access to Private5:52
And to connect to this instance, to this private instance, we have to do it from within the public instance. Since the public instance is in the same VPC as the private one, they can communicate with each other, while our machine on the other hand, cannot communicate with the private instance directly, because it's private. So let's go to the terminal, and before we may connect, we need to upload the .pem file we used to SSH into the public instance, since we selected this pair while creating the private instance as well. And to do that, we will use the scp command. So scp -i, provide the identity filename laracastec2.pem, then provide the name of the file we want.
Copy PEM via SCP6:29
And to do that, we will use the scp command. So scp -i laracastec2.pem, provide the identity filename laracastec2.pem, then provide the name of the file we want to upload, which is also laracastec2.pem. Then we provide the username, ubuntu, and we grab the public DNS hostname of the public instance. Paste it in the command, then provide the path where we want to upload the file. So home/ubuntu. Now let's execute the command, and the file was uploaded successfully. Let's ssh into the instance to verify, run ll, and here it is, we are good to go. So let's run ssh -i laracastec2.pem ubuntu, then go grab the private IP address.
SSH into Private Instance8:10
Here we go, connected. We are inside the private instance now. And if we log out, we will be inside the public instance. And if we log out, we will be on our machine again. Now we mentioned that private instances cannot connect to the internet unless we configure an app gateway. But in this VPC, we didn't configure one. So requests from the private instance to the public internet should fail. Let's verify that. Let's head to the terminal and ssh into the public instance, clear the terminal, and then
Verify No Internet Access9:50
We cannot upgrade or update any libraries unless we configure an app gateway. That's it for this lesson. I will see you in the next one.
