Connect To EC2 Instance via SSH – AWS EC2 Tutorial For Beginners (Amazon Web Services)
In the previous post, we learned how to create your first EC2 instance absolutely free on Amazon EC2 platform. In this post, we will learn how to connect to EC2 instance via SSH(Secure Shell Protocol). We have already set up our system in the cloud, we have allocated resources and installed the operating system but this system is in the cloud means it is sitting somewhere very far in one of the Amazon server farms. So how are we going to access this system?, the answer is SSH. We can access this system which is physically far away from you with the help of your system via a protocol known as SSH(Secure Shell Protocol). This process of accessing a system while being physically away from it is called remote administration.
What is SSH?
Secure Shell or SSH is a protocol used to transfer data securely between a client and a server over the internet or any public network. When a client connects to a server we need to make sure that the connection is secure so that we can securely exchange information without any obstructions or security threat. SSH provides a secure connection between a server and a client with the help of the cryptographic keys. SSH forms a secure tunnel between the client and the server through which data can be transferred securely. With the help of SSH, you can also execute commands on the server.
SSH works on port 22 of your system, and to use SSH on a Linux machine simply open terminal and execute the SSH command and in a windows system, you need SSH client such as putty.
Connect to EC2 Instance
You can connect to your EC2 instance in below Steps.
Step 1 – If you are using the Linux operating system to connect to your instance then you can skip this step. For windows users, we use git bash terminal which you can download and install from this site. After installing go ahead and open the git bash terminal application which is shown in the image below and for Linux users go ahead and open your terminal.
Step 2 – Log in to your AWS account and open your EC2 dashboard. Click on the instances section in the left sidebar and you will be shown all the instances which you have created. Right-click on the instance which you want to connect to make sure this instance is in running state.
Step 3 – You will see the very first option on the menu is connect. Click on the connect option from the menu and a dialog box will appear as shown below.
Step 4 – Now in the example section you will see they have provided with the command we need to connect to this instance copy this command.Now if you guys remember in the previous tutorial while creating instance we downloaded a file with “.pem” extension make sure you have that file on your system, this file is our private key which we will use to establish an SSH connection.
Step 5 – Now in your git bash or in terminal go to the location where you have kept the “.pem ” file with the help of the “cd” (Linux command to change directory) command and simply paste the command which you have copied earlier. you will be prompted asking “are you sure you want to connect?” type “Yes” and press enter and voila now you are connected to your EC2 instance via SSH.
Feel free to connect with me if you face any issues. In the next post, we will install PHP, MySQL and NGINX web server(LEMP Stack) on this system to host our website.