Connect with us

Uncategorized

How can I SSH into an AWS EC2 instance?

A note on security:

I will not suggest this method unless you are absolutely sure what you are doing. This method requires you to create and use an SSH key pair. You must download the SSH key pair file to your computer.

There is a potential security threat with this approach. Anyone who has the SSH Keypair can log in to the EC2 Instance. For example, in an office environment, if the keys are placed in a shared file storage or collaboration software, then other team members can access the key pairs.

How can I improve the security?

  1. Never ever, do not place the SSH pair in a shared location, like, git, network storage, etc.
  2. Update the security groups to block SSH access.
  3. Restrict SSH access to a specific or range of IP addresses. This method will work if you connect from your private computer or when your team connects from a known IP address range. If you are in the office, there is a chance that other teams’ IP ranges may also get included in the IP address range, so it may not be practical all the time.
  4. Avoid SSH connection completely and connect from the AWS Console using Session Manager or EC2 instance connect, where you can leverage IAM authentication.

How can I connect using SSH?

  1. Make sure you have the SSH keypairs
  2. Update the permissions for the SSH Key pair
  3. If you are using Linux/Mac, connect from a terminal using ssh utility

Update the permission for the PEM file:

chmod 400 my_ssh_keypair_file.pem

SSH into the EC2 instance:

Specify the name/location of the PEM file when invoking the ssh command, using -i option.

ssh -i "my_ssh_keypair_file.pem" ec2-user@ec2-100-32-21-239.us-west-2.compute.amazonaws.com

Where can I get more info?

You can find more details on this AWS documentation.

Continue Reading

Trending

Copyright © 2021 Rajan Panneer Selvam. Some of the content is derived from publically available information. For some of the resources I have obtained commercial licenses and you cannot use them in your projects. Before reusing any of the site content, please double-check for copyright issues. I am not responsible if you are infringing copyrights.