DEV Community

John  Ajera
John Ajera

Posted on

Securely Connecting to EC2 Instances with EC2 Instance Connect

🚀 Securely Connecting to EC2 Instances with EC2 Instance Connect

Amazon EC2 Instance Connect provides a secure and convenient way to access EC2 instances without requiring SSH key pairs or bastion hosts. This feature simplifies SSH access management by allowing users to securely connect via the AWS Console or CLI.

🔗 Key Benefits of EC2 Instance Connect

  • No SSH Key Management - Eliminates the need for manually managing SSH key pairs.
  • Enhanced Security - Restricts direct access, leveraging AWS IAM permissions.
  • On-Demand Temporary Access - Grants temporary SSH access to instances via an IAM policy.
  • Seamless AWS Console Integration - Connect directly from the AWS Console with one click.

📝 Prerequisites

Before using EC2 Instance Connect, ensure you have:

  • An EC2 instance running a supported OS (Amazon Linux 2, Ubuntu 20.04/22.04, Amazon Linux 2023 with manual setup).
  • AWS CLI installed (Setup Guide).
  • IAM permissions to use EC2 Instance Connect (ec2-instance-connect:SendSSHPublicKey).
  • Security group rules allowing EC2 Instance Connect traffic (AWS-managed prefix lists are recommended).

📝 Supported Operating Systems

EC2 Instance Connect is natively supported on the following Amazon-provided AMIs:

  • Amazon Linux 2
  • Ubuntu 20.04 and 22.04
  • Amazon Linux 2023 requires manual installation of EC2 Instance Connect and has been tested successfully.

Other operating systems may work with additional configuration.

🌐 How EC2 Instance Connect Works

When a user initiates a connection via AWS Console or CLI, AWS generates a temporary SSH key and injects it into the instance. The key is used for authentication, and access is granted only for the duration of the session.

📚 Terraform Sample Repository

For a working Terraform example demonstrating EC2 Instance Connect, check out:

👉 GitHub Repository: EC2 Instance Connect Terraform Demo

🔍 Troubleshooting EC2 Instance Connect Issues

❌ EC2 Instance Connect Option is Disabled in AWS Console

✅ Ensure the instance is in a public subnet and has a public IP.
✅ Verify that Amazon Linux 2 or Ubuntu is used (other OS may require manual setup).

❌ "Instance is Not Reachable" Error

✅ Confirm that EC2 Instance Connect Agent is installed and running (systemctl status ec2-instance-connect on Amazon Linux 2023).
✅ The instance must have outbound internet connectivity (NAT Gateway or AWS PrivateLink required for package updates).

📈 Summary

EC2 Instance Connect simplifies access to EC2 instances by providing temporary, keyless SSH access.

Want to try it out? Deploy your own EC2 Instance Connect setup using Terraform!

👉 GitHub Repository: EC2 Instance Connect Terraform Demo

Image of AssemblyAI tool

Transforming Interviews into Publishable Stories with AssemblyAI

Insightview is a modern web application that streamlines the interview workflow for journalists. By leveraging AssemblyAI's LeMUR and Universal-2 technology, it transforms raw interview recordings into structured, actionable content, dramatically reducing the time from recording to publication.

Key Features:
🎥 Audio/video file upload with real-time preview
🗣️ Advanced transcription with speaker identification
⭐ Automatic highlight extraction of key moments
✍️ AI-powered article draft generation
📤 Export interview's subtitles in VTT format

Read full post

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay