AWS Builder Center

Stop SSHing Into EC2: A Better Way to Manage Your Servers

Learn how AWS Systems Manager can replace traditional SSH-based server management, making EC2 access more secure, auditable, and easier to automate.

If you manage EC2 instances, SSH is probably one of the first things you set up.
But SSH comes with a familiar list of problems:
  • Opening port 22 to the internet
  • Managing SSH keys
  • Rotating credentials
  • Tracking who accessed which server
  • Setting up bastion hosts
There’s another approach: AWS Systems Manager Session Manager.

How it works

Instead of connecting directly to an EC2 instance:
Your Laptop
|
| SSH :22
v
EC2

you can use Systems Manager:
Your Laptop
|
v
AWS Systems Manager
|
v
EC2

The instance doesn't need an inbound SSH port open. Session Manager establishes the connection through the Systems Manager agent and AWS APIs.

Why this matters

This can significantly reduce your attack surface.
Instead of allowing:
0.0.0.0/0 → TCP 22

you can keep the instance inaccessible from the public internet while still allowing authorized administrators to connect.
It also gives you better visibility into administrative sessions and integrates with AWS Identity and Access Management (IAM).

Getting started

At a high level, you need:
  1. An EC2 instance with the SSM Agent.
  1. An IAM instance profile with the required Systems Manager permissions.
  1. Network connectivity from the instance to the required AWS Systems Manager endpoints.
  1. IAM permissions for administrators who need to start sessions.
You can then start a session using the AWS CLI:
aws ssm start-session --target i-xxxxxxxxxxxxxxxxx

No SSH key. No public IP requirement. No open port 22.

Final thought

SSH isn't inherently bad, and there are still situations where it's useful. But if your team is managing EC2 instances through SSH simply because that's how it has always been done, Systems Manager Session Manager is worth evaluating.
Sometimes improving cloud security isn't about adding another security tool.
It's about removing an unnecessary attack surface in the first place.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article