How SSM Session Manager connects you
Your IAM role is the key, and the instance connects out to AWS. Nothing connects in to the instance. The instance has no public IP, no open port 22, and no inbound security group rule. Use the steps under the diagram to follow one session.
Summary
- AWS Systems Manager Session Manager gives you a shell on an EC2 instance. You need no SSH key, no password, no bastion host and no open inbound port.
- IAM checks who you are. Your role must allow
ssm:StartSessionon the instance. This check is the only login. - The SSM Agent on the instance opens outbound HTTPS connections to AWS. AWS never opens a connection in to the instance.
- The Session Manager relay joins the WebSocket from your laptop to the WebSocket from the agent. The agent runs as root and starts the shell as
ssm-user. - CloudTrail records each session start. You can send the session output to S3 or CloudWatch Logs.
Each arrow points away from the side that opens the connection. Arrows go from your laptop to AWS and from the instance to AWS. No arrow goes in to the instance.
Why you need no key or password
SSH checks who you are on the instance. Session Manager checks who you are in IAM, before the instance does anything.
After IAM approves you, the agent starts the shell. The agent already runs as root, so the OS does not ask for a password. Your access is only as wide as your IAM policy.
What must be true
- The SSM Agent runs on the instance. Many Amazon AMIs include it.
- The instance role has
AmazonSSMManagedInstanceCore. - The instance can reach
ssm,ssmmessagesandec2messageson port 443, through a NAT gateway or VPC interface endpoints. - Your role allows
ssm:StartSessionon the instance. - Your laptop has the AWS CLI and the session-manager-plugin.
A minimal policy for you
{
"Effect": "Allow",
"Action": "ssm:StartSession",
"Resource": [
"arn:aws:ec2:*:*:instance/i-0abc123",
"arn:aws:ssm:*:*:document/SSM-SessionManagerRunShell"
]
},
{
"Effect": "Allow",
"Action": "ssm:TerminateSession",
"Resource": "arn:aws:ssm:*:*:session/${aws:userid}-*"
}
Other uses of the same tunnel
Port forwarding. AWS-StartPortForwardingSession sends a local port to a port on the instance. You can use it to reach a database, with no bastion host.
SSH over SSM. AWS-StartSSHSession carries SSH through the relay. Here SSM only carries the bytes, so SSH still needs a key.