Connect to EC2 instances
Connect to your EC2 instances with AWS Systems Manager Session Manager. A shell session needs no SSH keys and no open ports, so we recommend removing any security group rules that let SSH (port 22) or Remote Desktop (port 3389) in. Everything on this page works with those ports closed.
Open a session
- Console: in EC2, select the instance, choose Connect, then Session Manager, then Connect.
- Command line: install the Session Manager plugin for the AWS CLI, sign in as described in Sign in and roles then run the command below.
aws ssm start-session --target <instance-id>
A database or other port through an instance: run the command below, then connect your client to localhost:<local-port>. The database doesn't need to be reachable from the internet.
aws ssm start-session --target <instance-id> --document-name AWS-StartPortForwardingSessionToRemoteHost --parameters host=<endpoint>,portNumber=<port>,localPortNumber=<local-port>
Remote Desktop to Windows instances
In the console, open Systems Manager, then Fleet Manager, select the instance, and choose Node actions, Connect, then Connect with Remote Desktop. You sign in with a Windows account on the instance. To use your own Remote Desktop client instead, run the command below and connect the client to localhost:13389.
aws ssm start-session --target <instance-id> --document-name AWS-StartPortForwardingSession --parameters portNumber=3389,localPortNumber=13389
Tools that need SSH
scp, rsync, Ansible and VS Code Remote-SSH can run through Session Manager too. On Linux or macOS, add the lines below to ~/.ssh/config, then use the instance ID as the host name, for example ssh <user>@<instance-id>. SSH still checks your key, so the instance needs your public key just as it would for a direct connection. For Windows, see AWS's guide to SSH connections through Session Manager.
Host i-* mi-*
ProxyCommand sh -c "aws ssm start-session --target %h --document-name AWS-StartSSHSession --parameters 'portNumber=%p'"
Who can open sessions
| Access | Sessions |
|---|---|
| Read-only role | None |
| Operator role | Any instance in the account, plus Run Command and Fleet Manager |
| Builder role | Any instance in the account, plus Run Command and Fleet Manager |
What's recorded
Everything typed and shown in a shell session is recorded in the CloudWatch Logs group AWSAccelerator-sessionmanager-logs in your account, and a copy goes to UF's central log archive. SSH, Remote Desktop and port-forwarding sessions aren't recorded, but CloudTrail logs who started each one and when. A session with no activity for 20 minutes ends.
If a session doesn't start
If the instance has its own IAM role (instance profile) with Systems Manager permissions, such as AmazonSSMManagedInstanceCore, that role also needs two things: the policy AWSAccelerator-SessionManagerLogging, which is already in every account, and permission for logs:DescribeLogGroups on all log groups. Without them, sessions fail. If your Terraform or CloudFormation manages the role, add both there, or the next apply removes them.
We plan to add these permissions to every instance role automatically, and we'll update this page when that's in place.