
EC2 Says "Running." SSH Says "Connection Timed Out." Now What?
Your EC2 instance is running, but SSH keeps timing out. What could be wrong? Explore a practical troubleshooting guide covering Security Groups, Route Tables, Network ACLs, and SSH configuration. Learn how to find the problem step by step.
EC2 Says "Running." SSH Says "Connection Timed Out." Now What?
Imagine this situation.
You launch an Amazon EC2 instance.
You select your Amazon Machine Image, configure the instance, create a key pair, and wait for the instance to start.
Everything looks good.
- Instance state: Running
- Status checks: 2/2 passed
- Public IPv4 address: Assigned
You open your terminal and run:
ssh -i my-key.pem ec2-user@YOUR_PUBLIC_IPYou wait.
And then:
ssh: connect to host YOUR_PUBLIC_IP port 22:Connection timed outWhat happened?
The instance is running. AWS reports that its status checks are passing. So why can't you connect?
The important thing to understand is this:
Running does not automatically mean reachable.
Let's investigate the problem the way an infrastructure administrator would.
1. Start with the error message
Before changing anything, identify exactly what the SSH error tells you.
Not all SSH failures have the same cause.
Here are three common examples:
Connection timed out
The connection attempt receives no response within the expected time. This often points to a network path or firewall issue.
Connection refused
The destination is reachable, but the connection is actively rejected. SSH may not be listening on port 22, or a firewall may be rejecting the connection.
Permission denied (publickey)
The network connection is working, but authentication failed. The username, private key, or server-side SSH configuration may be incorrect.
This distinction is important because troubleshooting the wrong layer wastes time.
2. Check the Security Group
My first AWS-side check would be the Security Group attached to the EC2 instance.
A Security Group acts as a virtual firewall for your instance.
For a standard SSH connection, check the inbound rules.
Example:
Type | Protocol | Port | Source |
|---|---|---|---|
SSH | TCP | 22 | Your public IP/32 |
If port 22 is missing or your current public IP is not allowed, your connection may time out.
For a quick test, avoid opening SSH to the entire internet.
Using
0.0.0.0/0 exposes port 22 to every IPv4 address and is not a good permanent solution.Security tip: Restrict SSH access to your trusted IP address or use AWS Systems Manager Session Manager where appropriate.
3. Verify the Network Route
Your Security Group may be correct, but the instance may still be unreachable.
Now check the VPC networking configuration.
For direct SSH access over the internet, verify:
- The instance is in the intended subnet.
- The subnet's route table has a route to an Internet Gateway.
- The VPC has an attached Internet Gateway.
- The instance has a public IPv4 address or another valid public connectivity path.
A typical public subnet route table includes:
Destination Target172.31.0.0/16 local0.0.0.0/0 igw-xxxxxxxxThe Internet Gateway provides the internet connectivity path. A public IPv4 address alone is not sufficient if the routing configuration is incorrect.
4. Don't Forget Network ACLs
This is where troubleshooting gets interesting.
Network ACLs (NACLs) operate at the subnet level.
Unlike Security Groups, Network ACLs are stateless.
That means you must consider both directions of the connection.
For SSH, verify that:
- The inbound rules allow TCP port 22 from your source IP.
- The outbound rules allow the return traffic to the client's ephemeral port range.
A restrictive NACL can block a connection even when the Security Group is correctly configured.
This is why checking only one firewall is not enough.
5. Investigate the Operating System
Suppose all AWS network configurations look correct.
What next?
The problem may be inside the EC2 instance.
Possible causes include:
- The SSH service is stopped.
- The operating system firewall blocks port 22.
- SSH is configured to listen on a different port.
- The instance has a boot or operating system problem.
If you can access the machine through another management method, such as Systems Manager Session Manager, inspect the SSH service.
On a Linux system using systemd:
sudo systemctl status sshdIf the service is stopped, investigate why before restarting it.
You can also check whether SSH is listening:
sudo ss -tlnp | grep ':22'The exact service name and commands can vary depending on the Linux distribution.
6. What if the network works but authentication fails?
Now imagine you have solved the connectivity issue.
You try SSH again, but receive:
Permission denied (publickey).This is a different problem.
Check three things:
1. The username
The default SSH username depends on the AMI.
For example:
- Amazon Linux:
ec2-user
- Ubuntu:
ubuntu
2. The private key
Make sure you are using the private key corresponding to the key pair configured for the instance.
3. File permissions
On Linux, SSH may reject a private key with overly permissive file permissions.
You can correct them with:
chmod 400 my-key.pemDo not confuse an authentication failure with a network connectivity failure.
7. My EC2 SSH Troubleshooting Checklist
If I were troubleshooting this incident, I would follow this order:
- Read the exact SSH error.
- Check the EC2 instance state and status checks.
- Verify the public IPv4 address.
- Inspect the Security Group inbound rules.
- Check the subnet route table and Internet Gateway.
- Review Network ACL inbound and outbound rules.
- Investigate the SSH service and operating system firewall.
- Verify the username and private key if authentication fails.
Instead of randomly changing AWS settings, investigate one layer at a time.
Final Thoughts
An EC2 instance can be running and still be completely unreachable.
That is one of the most important lessons when learning cloud networking.
Troubleshooting is not about opening every port or disabling every firewall until something works.
It is about understanding the traffic path, identifying where communication stops, and fixing the actual cause.
A good administrator doesn't just ask whether a server is running. They ask whether the entire communication path is working.
Let's discuss!
When your EC2 instance is running but SSH times out, what do you check first?
- Security Groups
- Route Tables and Internet Gateway
- Network ACLs
- The operating system and SSH service
I'd love to hear how other AWS builders approach this problem.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article