# How to connect to EC2 with Session Manager

How-to guides · Updated 17 November 2026

**Short answer:** Session Manager gives you a shell on an instance with no SSH keys and no inbound ports. The instance needs the SSM Agent (preinstalled on Amazon Linux and many other AWS-provided AMIs), an instance profile with the AmazonSSMManagedInstanceCore policy (or Default Host Management Configuration), and outbound access to Systems Manager. Then choose Connect in the EC2 console and use the Session Manager tab, or run aws ssm start-session --target i-0123456789abcdef0.

## Set-up checklist

| Requirement | How to check or fix |
|---|---|
| SSM Agent running | Installed by default on Amazon Linux 2 and 2023 and on recent Ubuntu and Windows AWS AMIs; check with `systemctl status amazon-ssm-agent` (or the snap service on Ubuntu) |
| IAM permissions for the instance | Attach an instance profile whose role has `AmazonSSMManagedInstanceCore`, or enable Default Host Management Configuration in Systems Manager for the Region |
| Network path to Systems Manager | Outbound HTTPS via an internet gateway or NAT, or interface VPC endpoints for `ssm`, `ssmmessages` and `ec2messages` in private subnets |
| Your permissions | `ssm:StartSession` on the instance (and the session document) |
| CLI only | The Session Manager plugin installed alongside the AWS CLI |

After attaching a role, give the agent a few minutes to register, or restart it.

## Connect from the console

1. Open the Amazon EC2 console, select the instance and choose **Connect**.
2. Choose the **Session Manager** tab and then **Connect**. A browser terminal opens.

If the Connect button is greyed out on that tab, the instance isn't registered as a managed node yet; work through the checklist. You can also start sessions from the Session Manager page in the Systems Manager console.

## Connect from the CLI

```
# Is the instance managed and online?
aws ssm describe-instance-information \
  --filters Key=InstanceIds,Values=i-0123456789abcdef0 \
  --query 'InstanceInformationList[].[InstanceId,PingStatus,AgentVersion,PlatformName]' --output table

# Shell
aws ssm start-session --target i-0123456789abcdef0

# Forward local port 13389 to RDP on the instance
aws ssm start-session --target i-0123456789abcdef0 \
  --document-name AWS-StartPortForwardingSession \
  --parameters '{"portNumber":["3389"],"localPortNumber":["13389"]}'

# Reach a private database through the instance
aws ssm start-session --target i-0123456789abcdef0 \
  --document-name AWS-StartPortForwardingSessionToRemoteHost \
  --parameters '{"host":["orders-db.abc123xyz.eu-west-2.rds.amazonaws.com"],"portNumber":["5432"],"localPortNumber":["15432"]}'
```

`PingStatus` should be `Online`. Sessions start as the `ssm-user` account on Linux by default; use `sudo` as needed, or configure Run As in Session Manager preferences.

## When it won't connect

- **Instance not listed as managed:** almost always the role or the network path. A private subnet without NAT needs all three VPC endpoints, with a security group allowing HTTPS from the instance.
- [TargetNotConnected](https://cloudconsole.dev/errors/ssm-start-session-targetnotconnected): the agent was registered but isn't reachable now; check the agent is running and the instance can still reach the endpoints.
- **"SessionManagerPlugin is not found":** install the plugin on your computer.
- **Old agent:** very old agents miss features such as port forwarding to remote hosts; update the agent.

## Why bother instead of SSH

- No inbound security group rules and no bastion host to patch.
- Access is controlled by IAM and can be limited by instance tag.
- Sessions are recorded in CloudTrail, and session output can be logged to CloudWatch Logs or S3.
- No long-lived SSH keys to rotate or leak; see [Permission denied (publickey)](https://cloudconsole.dev/errors/ec2-permission-denied-publickey) for the problems this avoids.

## Questions

### How do I connect to EC2 with Session Manager from the AWS CLI?

Install the Session Manager plugin, then run aws ssm start-session --target with the instance ID. The instance must be online as a managed node.

### Do I need a public IP for Session Manager?

No. The instance needs outbound access to Systems Manager, through a NAT gateway or through VPC endpoints. No public IP or inbound rule is required.

### Can I use SSH or SCP over Session Manager?

Yes. With the AWS-StartSSHSession document configured as a ProxyCommand in your SSH config, ssh and scp tunnel through Session Manager, though you then need SSH keys again.

## When this happens away from your desk

A shell on a phone is rarely pleasant, but knowing whether an instance is reachable is useful. CloudConsole, a phone app for AWS, is built to show instance health and managed-node status on your phone.

[About the CloudConsole app](https://cloudconsole.dev/aws-console-app) · [Download on the App Store](https://apps.apple.com/app/cloudconsole-for-aws/id6835419710)

## Sources

- [AWS Systems Manager Session Manager](https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager.html)
- [StartSession API reference](https://docs.aws.amazon.com/systems-manager/latest/APIReference/API_StartSession.html)

## Related

- [aws ssm start-session](https://cloudconsole.dev/cli/ssm-start-session)
- [SSM Session Manager: TargetNotConnected](https://cloudconsole.dev/errors/ssm-start-session-targetnotconnected)
- [ssh: connect to host ec2 port 22: Connection timed out](https://cloudconsole.dev/errors/ec2-ssh-connection-timed-out)
- [Permission denied (publickey) when connecting to EC2 over SSH](https://cloudconsole.dev/errors/ec2-permission-denied-publickey)
- [How to exec into an ECS container](https://cloudconsole.dev/how-to/ecs-exec-into-container)
- [How to run a command on multiple EC2 instances](https://cloudconsole.dev/how-to/run-command-on-multiple-ec2-instances)

---

Source: https://cloudconsole.dev/how-to/connect-to-ec2-with-session-manager

CloudConsole is an independent iPhone and Android app for Amazon Web Services by Cloudconcur Ltd. It is not affiliated with Amazon Web Services.
