How to close an AWS security group open to the internet
A security group open to 0.0.0.0/0 on SSH, RDP or a database is found and attacked within minutes. Here's how to find and lock it down.
Steps
- List open groups: aws ec2 describe-security-groups --query "SecurityGroups[?IpPermissions[?IpRanges[?CidrIp=='0.0.0.0/0']]].GroupId".
- Remove the open rule: aws ec2 revoke-security-group-ingress --group-id <id> --protocol tcp --port 22 --cidr 0.0.0.0/0.
- Authorize a narrow source instead: --cidr <your-office-or-vpn>/32, or reference another security group.
- For admin access, prefer AWS Systems Manager Session Manager over any public SSH/RDP port.
How to verify
- Re-run the describe-security-groups query — the group should no longer appear.
- From outside your allowed range, the port should no longer connect.
FAQ
- Which ports are safe to leave open?
- Only ports a public service genuinely needs — usually 80 and 443 behind a load balancer. Never admin ports or databases.
Have SkyShield check this for you
SkyShield finds this across every server and cloud account and shows the fix in plain words. Free for one server, then from $49 per server a month. Start free.