Connect to an AWS EC2 Instance via SSH

Sam Julien
InstructorSam Julien
Share this video with your friends

Social Share Links

Send Tweet

When you hit the connect button to your instance, AWS actually gives you instructions and copyable commands for you to run to connect to your instance.

After connecting to your instance you will have access to a real live server! From there, the first thing you'll almost always want to do is check for updates and upgrade them using sudo apt update and sudo apt upgrade

Instructor: [0:00] Now that we've got an EC2 instance up and running. Let me show you how you would connect to it using SSH in order to do things like install Node and get a server up and running. Thankfully, AWS gives you some instructions on how to do this.

[0:15] If I click this Connect button, it's going to bring up some instructions for me. It's even going to give me a command that I can use to connect to my EC2 instance. Before we do that, though, remember, in the last video, we created a public and private key that we needed to be able to access the instance.

[0:36] In order for that to work, we need to change the permissions of this key to use it properly. We're going to copy this command, which is the chmod command in Linux. We're going to go over to our terminal.

[0:51] Over in our terminal, I'm going to go ahead and navigate to my Downloads folder because I have my key in that folder. I'm going to paste in that modification command. Basically, what we're doing here is making our key able to be read by our user. I'll hit Enter.

[1:09] Now, I'll go ahead and go back to our connection instructions. You can see, down a little bit here, we're going to be connecting to our EC2 instance using its public DNS. Luckily, AWS gives us the full command that we can just copy here.

[1:24] One thing I'll point out is that you can see that the username for the root user is Ubuntu, and you can see the public IP address hidden in this connection string here. If we were to go look at our public IP address, it would be 3.137, etc., etc. Then following that is the regional address for this EC2 instance.

[1:46] Now that that's copied, let's go back over to our terminal. I'll paste that command in and hit Enter. Since it's the first time that I'm connecting to this instance, I need to say yes to this prompt asking me if we want to continue. It might take a second, but lo and behold, here we are.

[2:03] If I scroll up a little bit, you can see that it says "Welcome to Ubuntu 20.04." We're actually connecting to a real live Ubuntu server in a warehouse somewhere in Ohio. That's pretty cool. Now, we're connected, and we could do whatever we want.

[2:21] The first thing you're almost always going to do is check for updates and upgrade them. You would run sudo apt update, which is a Linux package manager. This command basically just goes and gets the list of available updates for your server. It usually just takes a second.

[2:39] Then, follow through on the upgrade, you would run sudo apt upgrade. The sudo command there is basically running as a root user -- stands for Super User Do -- and it's going to ask if we want to continue. We'll say yes, and we'll go ahead and let that run. It might take a second. I'm going to go ahead and fast-forward here so you don't have to sit here and watch it. There we go.

[3:01] After a few minutes, all of those updates are done, and we're ready to install anything else that we wanted to do on this server. From here, you'd want to do things like create a user to be able to run whatever server you're going to install, install some software, like nginx, to control the traffic on the server, and then install things like Node to actually get your server up and running.