How to securely connect EC2 via SSH with AWS Systems Manager

Modern best practice to connect Amazon EC2 instance via SSH without SSH key/password and with closed inbound 22 port. AWS Systems Manager Session Manager tutorial.

Table of Contents

Step 1: Launch Amazon EC2 Instance

Step 2: Create AWS IAM Role

Step 3: Connect Amazon EC2 via SSH

$ aws ssm start-session --target INSTANCE_ID
$ aws ssm start-session --target i-06fd9f063a7cf53fd

Extra: Connect using SSH command and SSH key

$ sudo yum install -y https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/linux_amd64/amazon-ssm-agent.rpm
$ ssh -i SSH_KEY ec2-user@INSTANCE_ID
$ ssh -i key.pem ec2-user@i-077b1f947c98988d5

Sources

Python Developer and Artificial Intelligence Engineer