DEV Community

Ajit Singh for This is Learning

Posted on • Updated on

SSH into your EC2 instances

What is ssh?

SSH is a remote management protocol through which you connect to your remote servers and modify them. This allows you to access your remote servers securely.

So let us see how we can connect with our EC2 instances securely using SSH

  • First see what your public IP address is from your ec2-instance.
    Instance details

  • After that if you are a Linux or Mac user open your terminal and run the following command ssh username@public-ip for me the public IP is 13.233.33.232 and default ec2 user is ec2-user so the final command becomes

ssh ec2-user@13.233.33.232
Enter fullscreen mode Exit fullscreen mode
  • Once you run it you will get the following message
The authenticity of host '13.233.33.232 (13.233.33.232)' can't be established.
ECDSA key fingerprint is SHA256:BudJr8YMxFu8ylCGragb1BfW04/VI6+hX017siHF19w.
Are you sure you want to continue connecting (yes/no/[fingerprint])?
Enter fullscreen mode Exit fullscreen mode

Type yes and agree to it. After this you will get a message like this

Warning: Permanently added '13.233.33.232' (ECDSA) to the list of known hosts.
ec2-user@13.233.33.232: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).

Enter fullscreen mode Exit fullscreen mode

It's still not working but that is a good thing because if this allows us to ssh then anyone can ssh into our EC2 instance if he knows our public IP.

  • In the last exercise we downloaded a pem file while creating our EC2 instance we need to use that pem file to login into out EC2 instance. to use that we run ssh -i path-to-file username@public-ip
ssh -i EC2test.pem ec2-user@13.233.33.232
Enter fullscreen mode Exit fullscreen mode
  • It will still not allow you to signin and because permissions are to open. This is because right now our EC2 test.pem file permissions 0644 which allows any user to write on it. EC2 is complaining that even the root user should have read only permission so that no one can change our key file.

  • This can be easily resolved just do

chmod 400 EC2test.pem
Enter fullscreen mode Exit fullscreen mode
  • Which resolves the permissions issue now run the above command again.
ssh -i EC2test.pem ec2-user@13.233.33.232
Enter fullscreen mode Exit fullscreen mode
  • Now you will be logged into your ec2 instance.

This is it for how to remote access to your ec2 instance. In the next article in the series we will study more about the different EC2 instances and there advantages.

Top comments (0)