β Step-by-Step: Enable AWS SSM on Ubuntu 22.04 EC2
π 1. Verify Prerequisites
Requirement | Details |
---|---|
β EC2 in VPC | Ubuntu 22.04-based EC2 instance |
β Internet access | Via NAT Gateway or VPC Interface Endpoints |
β IAM Role | Must have SSM permissions |
β Port 443 open | Outbound from instance (HTTPS) |
π οΈ 2. Attach IAM Role with SSM Permissions
- Create IAM Role with the following AWS-managed policy:
Policy: AmazonSSMManagedInstanceCore
- Attach the IAM Role to your EC2 instance.
π¦ 3. Install the SSM Agent (if not pre-installed)
As of 2024+, Ubuntu 22.04 on EC2 often includes SSM Agent pre-installed, but verify:
β A. Check status:
sudo systemctl status amazon-ssm-agent
π B. If not installed, run:
# Install dependencies
sudo apt update
sudo apt install -y snapd
# Install SSM Agent via Snap (recommended method)
sudo snap install amazon-ssm-agent --classic
# Start the agent
sudo systemctl enable --now snap.amazon-ssm-agent.amazon-ssm-agent.service
β³ Alternative via .deb
:
wget https://s3.amazonaws.com/amazon-ssm-region/ubuntu_amd64/amazon-ssm-agent.deb
# Replace 'region' with your AWS region, e.g., 'ap-south-1'
sudo dpkg -i amazon-ssm-agent.deb
sudo systemctl enable amazon-ssm-agent
sudo systemctl start amazon-ssm-agent
π 4. Verify Agent is Running
ps aux | grep ssm-agent
sudo systemctl status amazon-ssm-agent
π 5. Ensure Outbound Internet or VPC Endpoints
β Option A: NAT Gateway
Ensure private subnet routes 0.0.0.0/0
to a NAT Gateway.
β Option B: VPC Endpoints (if no NAT)
Create Interface VPC Endpoints for:
com.amazonaws.ap-south-1.ssm
com.amazonaws.ap-south-1.ec2messages
com.amazonaws.ap-south-1.ssmmessages
Allow traffic on port 443
to these endpoints via security groups.
π 6. Connect via Session Manager
A. From Console:
AWS Console > Systems Manager > Session Manager > Start Session
B. From AWS CLI:
aws ssm start-session --target i-0123456789abcdef0
β 7. (Optional) Enable Logging + Auditing
For enterprise governance, enable:
- CloudTrail logging
- SSM Session Logging (to S3 or CloudWatch)
Go to: Systems Manager > Session Manager > Preferences > Create Logging Configuration
π Troubleshooting Checklist
Issue | Fix |
---|---|
SSM agent not starting | Check service logs: journalctl -u amazon-ssm-agent |
EC2 not showing in SSM | IAM role missing or misconfigured |
No outbound access | Check NAT/VPC Endpoints |
Access denied in CLI | IAM user/role needs ssm:StartSession |
π§° Example IAM Policy for SSM Access (CLI Users/Admins)
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"ssm:StartSession",
"ssm:TerminateSession",
"ssm:DescribeSessions",
"ssm:GetConnectionStatus"
],
"Effect": "Allow",
"Resource": "*"
}
]
}