- Newest
- Most votes
- Most comments
Hello.
Does the same problem occur when connecting from a different OS or a different PC?
For example, does the error occur when connecting from Mac OS or terminal software such as Tera Term?
Based on your detailed description, you're experiencing an unusual SSH connection timeout issue where the initial connection and fingerprint verification succeed, but then the connection times out. This suggests that the initial TCP handshake is working, but something is interrupting the connection afterward.
Since you've already verified that:
- Security groups are properly configured
- Network ACLs are correctly set up
- Firewalls are disabled
- SSH service is running
- The instance is reachable (ping works)
- The initial connection starts (you get the fingerprint prompt)
Here are some potential solutions to try:
-
MTU Issues: You mentioned adjusting your MTU to 1360, which is a good step. Network issues related to MTU can cause connection problems after the initial handshake. Try experimenting with different MTU values.
-
SSH Client Configuration: Try adding verbose output to your SSH command to see where exactly the connection is failing:
ssh -v -i "path/to/key.pem" ubuntu@your-ec2-ip
This will show you detailed information about the connection process.
-
SSH Server Configuration: Connect to your instance using the AWS EC2 Serial Console or Systems Manager Session Manager, and check the SSH server configuration file (/etc/ssh/sshd_config) for any unusual settings that might be causing timeouts.
-
TCP Keepalive Settings: Try adding keepalive options to your SSH command:
ssh -o ServerAliveInterval=60 -i "path/to/key.pem" ubuntu@your-ec2-ip
-
Alternative SSH Client: Try using a different SSH client like PuTTY or MobaXterm to see if the issue is specific to your current client.
-
Check System Resources: High CPU usage or memory pressure on the EC2 instance could cause SSH connections to time out after initial handshake. Check the instance's resource utilization.
-
Network Path Issues: There might be a network device between your computer and the EC2 instance that's allowing the initial connection but blocking subsequent packets. Try connecting from a completely different network.
-
Try EC2 Instance Connect: As a workaround, you could use EC2 Instance Connect through the AWS Management Console to access your instance while troubleshooting the SSH issue.
Since you've already tried many common solutions, this appears to be a more complex networking or configuration issue that might require deeper investigation.
Sources
Can't connect to Linux instance even after the health status checks pass | AWS re:Post
Port 22: Connection Time Out Issue | AWS re:Post
ssh operation timed out | AWS re:Post
- I tried but nothing changed
- It's showed same problems: type -1 error with key and connection time out 22 port
- I checked all configuration again, and find nothing special. Everything is allowed and things needed to be uncommented are uncommented too.
- Tried PS C:\Windows\system32> ssh -o ServerAliveInterval=60 -i "C:\Users\Work.ssh\keyy.pem" ubuntu@my-ip*** ssh_dispatch_run_fatal: Connection to my-ip**port 22: Connection timed out - so I had same error
- tried Putty with .ppk key format and different settings like diffie-hellman-group14, but same result: connection starts, and than '"Network error: Software caused connection abort"
- Interesting idea, but not my situation at all: my home pc and server pc have enough resources still.
- When I tried different network, same problem: ssh connection time out.
- I always use it, and it 100% works. So thanks for the answering, but it didn't wok at all. I tried everything and still don't understand where my "wire" breaks.
UPD: I created a new Linux Ubuntu server with a new key and same settings, and the problem still same too
Thanks for answering! I tried Tera Term, and the problem was same as usually: my server opened, but after this did nothing and no info about server etc, just blank screen and only loading. And connection stopped after some time (connection time out). This problem appears with any device or OS: I tried Windows pc and Android mobile, for example. However, I tried change internet connection: I was connected all the time to my mobile internet provider (sim card) (using WiFi module for pc and straight forward connection to the phone). So I tried to use my home provider connection - and my problem partly solved! My server is available from any device without vpn or anything else, just using home provider connection. But I have to use mobile internet provider usually, and don’t have an opportunity to use always my home provider connection. So now I want to find the reason of this server behaviour. Could it be something like different MTU size for mobile internet and home internet, I don’t know? Also I found some information that versions 24 and 22 of Ubuntu, which I using now as server, have some bugs with internet connection because of file error. But I don’t think it is my case, because of home provider connection works, isn’t it?
I tried it with my AWS account and was able to connect via SSH successfully. The region I'm using is the Tokyo region. By the way, does the same error occur if you change the EC2 OS to something like Amazon Linux 2023 instead of Ubuntu? If it only occurs with Ubuntu, there may be a problem with the AMI you are using.