- Newest
- Most votes
- Most comments
The network ACLs are uni-directional, that is, the return traffic are not allowed by default. The permissions, though overly permissive, should allow you to connect via ssh. The only change you need to make is update outbound network ACL and allow ephemeral ports. What this means is you can connect to the EC2 via ssh, but currently, the EC2 cannot reply to our traffic.
Outbound port range: 1024-65535, ALLOW, Protocol: TCP, Destination: 0.0.0.0/0
Also, I highly recommend you review your security groups as it is open to the world. At a minimum, restrict the ssh access to only your IP.
Based on the information you've provided, it seems you've covered many of the common issues that can prevent SSH access to an EC2 instance. However, there are a few additional areas we can explore:
-
VPC and Internet Gateway: Ensure that your EC2 instance is in a public subnet within your VPC, and that the VPC has an Internet Gateway attached. Also, check that the route table associated with your subnet has a route to the Internet Gateway (usually 0.0.0.0/0 pointing to the IGW).
-
Instance's Public IP: Verify that you're using the correct and current public IP address of your instance. Public IPs can change if you stop and start the instance (unless you're using an Elastic IP).
-
SSH Key: Confirm that you're using the correct private key (.pem file) that corresponds to the key pair associated with the instance when you launch it.
-
OS-level Firewall: Sometimes, the operating system's firewall (like iptables on Linux) might be blocking incoming connections. This would require accessing the instance through other means to check and modify.
-
EC2 Instance Connect: Try using EC2 Instance Connect from the AWS Management Console. This method bypasses some local network issues and can help isolate whether the problem is on the instance side or your local network.
-
Systems Manager Session Manager: If configured, you could try accessing your instance using AWS Systems Manager Session Manager, which doesn't require SSH access.
-
Check System Logs: Review the system logs of your EC2 instance from the AWS Management Console. This might provide clues about any issues preventing SSH access.
If none of these solutions work, you might want to consider:
- Creating a new instance in the same or a different subnet to isolate the issue.
- Using the EC2 Rescue for Linux tool, which can help diagnose and fix issues with Linux instances.
- Contacting AWS Support for more in-depth assistance, especially if you suspect an issue with AWS infrastructure.
Remember to make changes one at a time and test after each modification to identify which change resolves the issue. Once you regain access, review and tighten your security configurations to prevent future access issues while maintaining proper security practices.
Sources
Unable to SSH into AWS EC2 Instance – Connection Timed Out & Forgot Credentials | AWS re:Post
EC2: Cannot connect anymore via Instance Connect or SSH command line | AWS re:Post
Can't connect to ec2 instance | AWS re:Post
The problem lies with your NACL configuration. While it allows SSH inbound traffic to port 22 (rule 101), it doesn't allow the outbound traffic to the SSH client on the list of ephemeral ports (1024-65535) that the client needs for communication with the SSH server. Currently, it denies all outgoing traffic from the instance (rule number *) except for the specifically listed ports (80, 22, and 443).
To resolve this, you need to allow outbound traffic to the list of ephemeral ports (1024-65535) by adding a new rule in the Outbound ACL Rules.
Adding the ephemeral port range to my Security groups outbound rules did the trick. Now I'm experiencing something new. NGINX is running but I can't reach my site through the Public IPv4 address. This was working before and I can test this working by doing: curl 127.0.0.1

Agree, the network ACLs must allow inbound SSH traffic on port 22 but also allow outbound traffic to the ephemeral ports (1024-65535). Source
Nice - this did the trick. Thank you!