Connect your EC2 instance with terminal

Hello Friends, In the last tutorial we have learned how to create EC2 instance, Now we will learn how to connect EC2 instance with terminal

You will need to know the location of your key pair you created when you launched your instance. Usually this will be in your “Downloads” folder, but you may want to move it elsewhere.

For Mac OS & Linux Users

First of all we will change the PEM file permission. We will give it to 400

Next, Open your terminal and run the below command to change the permission

chmod 400 **/path/to/your/key/filename.pem

Next, Run below command to connect with EC2 instance

ssh -i /path/to/your/key/filename.pem [email protected]

Here ubuntu is the default usrename created by aws. Change ipaddress string with your ipaddress. You can find this under EC2 instance

For Windows

To connect with ec2 instance you need putty. If you don’t have the PuTTY software installed on your system, you will need to download it from Be sure to select the entire package as shown below, as it will include all the needed utilities such as puttygen and pageant.

Generate ppk file

Next, open PuTTYgen, On the PuTTYgen dialog box, click the Load Button and then select the .pem file that you downloaded from AWS. Note: when browsing for your pem file be sure to select All Files in the dropdown list that is located to the right of the File name field. PuTTYgen will then load and convert your file.

Next, click on “Save private key”. You will receive a warning message asking if you want to save this key without a passphrase. Be sure to select Yes.

Provide a name for your ppk file and click save.

Connect with Server

Next, Open PuTTY

Enter hostname

Enter your Host Name into the appropriate field. This will be in the format of: [email protected]_dns_name. Be sure to specify the appropriate user name for your AMI type. For example:

•For an Amazon Linux AMI, the user name is ec2-user.

•For a RHEL AMI, the user name is ec2-user or root.

•For an Ubuntu AMI, the user name is ubuntu or root.

•For a Centos AMI, the user name is centos.

•For a Fedora AMI, the user name is ec2-user.

•For SUSE, the user name is ec2-user or root.

•Otherwise, if ec2-user and root don’t work, check with the AMI provider.

Here is an example for connecting to an Amazon Linux AMI:

Next, click on the + button next to the SSH field to expand this section. Then click on Auth (which stands for authenticate) and enter the name of your private key file (i.e. the ppk file) where it says Private key file for authentication (if you click on browse you can easily search for the directory where you have stored it).

Lastly, click on Open to start your SSH session.

Note: if this is the first time that you are logging into the instance, you will receive the following alert.

Click on Yes to continue.

Congrats!! You have successfully connected with the EC2 instance

In the next tutorial we will learn how to install Apache and Nginx server in the EC2 instance and launch our website

Comments are closed.