EC2 offers different ways of connecting to an EC2 instance from a remote device. Among those, SSH connection is the commonly used method in both Linux and MacOS systems, and the EC2 instance connect is available to all platforms as it is running in a browsing session.

SSH client connect

SSH is one of the most important function, it allows you to control a remote machine using the command line. To establish a SSH connection, it requires a key pair you created during EC2 instance setup.

  1. Locate your key file with an extension pem for use with Open SSH.
  2. Change the key file permission to user read-only for key protection
chmod 400 <key file>
  1. Connect to the EC2 instance using the default user user-ec2 and the public IP address of your EC2 instance
ssh -i <key file> user-ec2@<EC2 public IP address>

Once you connected to the EC2 instance, you can disconnect from it by either type in exit in the CLI or by pressing Ctrl + G.

EC2 Instance connect

You can establish a EC2 instance connect from the AWS Management Console. The EC2 instance connect is established upon SSH, therefore you have to allow SSH related security group policies for making an EC2 instance connect.

Connection trouble shooting

  • Timeout If there is a connection timeout error, there is a security group issue. Any timeout raised is related to security groups or firewall. Make sure your security group has allowed traffics from the SSH port 22 and all related firewall policies no matter corporate or personal have to give way for SSH connections.
  • SSH doesn’t work for Windows If you experienced ssh command not found that means you have to use Putty for establishing connection.
  • Connection refused This means an instance is unreachable; try to restart the instance or create a new instance and make sure you are using Amazon Linux 2.
  • Permission denied If you encountered Permission denied (publickey,gssapi-keyex,gssapi-with-mic), this means either:
    • You are using the wrong security key or not using a security key. Look at your EC2 instance configuration to make sure you have assigned correct key to it.
    • You are using the wrong user. Make sure you have started an Amazon Linux 2 instance, and make sure you are using the correct user or either using the default user user-ec2.

Back to parent node: EC2 - Elastic Compute Cloud

Cloud_computingAWS_CLF-C02 AWSEC2Connect_to_EC2