Connect to EC2 Without Public SSH or RDP Using Session Manager

How do I connect to a private EC2 instance without opening port 22 or 3389?
Run SSM Agent with an authorized EC2 instance profile and give the instance outbound HTTPS access to the required Systems Manager endpoints. An authorized operator can then start a Session Manager shell through the console or AWS CLI.

Configure the instance side
Use an Amazon Linux 2023 instance in a private subnet in us-east-1. Attach an EC2-trusted role via an instance profile with AmazonSSMManagedInstanceCore, or the equivalent approved permissions. Use a current SSM Agent. For a no-NAT example create interface endpoints com.amazonaws.us-east-1.ssm and com.amazonaws.us-east-1.ssmmessages. Enable private DNS and VPC DNS support. Allow TCP 443 inbound on the endpoint security group from the instance security group and TCP 443 outbound from the instance to the endpoints. Older agent and Region combinations can use ec2messages. Optional session logging, encryption and agent updates have separate service connectivity and permissions requirements.
Give the operator a narrowly scoped session policy
For example, grant ssm:StartSession only for approved instances and the allowed session document, with resume and terminate permissions scoped to the operator’s own session resources. Grant the appropriate read permissions for console discovery. Review shell privileges on the instance. Session run-as settings and log delivery are configured separately. A role on the instance and the identity of the operator control different actions.
Start and verify a shell
On the workstation, install AWS CLI and the Session Manager plugin for CLI access. Replace the sample instance ID. In the console, use Systems Manager Session Manager or EC2 Connect with the Session Manager option. After connecting, use hostname and whoami and compare the results with your intended instance and shell identity. Test from the real operator account before closing alternative access paths.
aws ssm describe-instance-information --region us-east-1 --filters Key=InstanceIds,Values=i-0123456789abcdef0
aws ssm start-session --region us-east-1 --target i-0123456789abcdef0
Diagnose an offline node
Check account, Region and instance state first. With established recovery access, check systemctl status amazon-ssm-agent on Amazon Linux and inspect /var/log/amazon/ssm/amazon-ssm-agent.log. On Windows check Get-Service AmazonSSMAgent and the logs under C:\ProgramData\Amazon\SSM\Logs. Check instance profile attachment and private endpoint DNS resolution. A DNS lookup should return private endpoint addresses for this architecture. If DNS works but port 443 times out, inspect the endpoint security group and subnet ACLs. If the instance is online but an operator receives AccessDenied, check the operator authorization, the selected document, and applicable policy boundaries.
Frequently asked questions
Does the EC2 instance need a public IP?
PrivateLink or appropriate outbound access can connect the agent without a public IP.
Does the CLI require a plugin?
Yes, install the Session Manager plugin on the workstation running the AWS CLI session command.
Why is my instance online but I cannot connect?
Check operator IAM and session document permissions as well as the ssmmessages path.
Can I use Windows?
Session Manager supports a Windows shell on a supported managed node with the agent running.
Does logging capture a tunneled SSH session?
Session content logging has limitations for tunneling and SSH over Session Manager. Check the selected session type.
Comments
Post a Comment