Skip to content

EC2 ssh closes my connection, but not for others

0

I don't know when it started but now when I access a EC2 instance (Amazon Linux 2023) through ssh and if I don't write anything within 60 seconds, my terminal freezes. I assume that I get disconnected, but there's no feedback related to that and the only way to close the terminal is to close the window, can't do Ctrl+D.

I read that AWS instances disconnect clients when they do not receive any data within a specified period of time, but I never had this problem until now. What's more strange is that this is only happening to me, and not my coworkers. I've compared the /etc/ssh/ssh_config files, and we all have the same (the default one without the ServerAliveInterval (...)

asked 2 years ago674 views

1 Answer
0

The issue you're experiencing with your SSH connection to your EC2 instance closing after 60 seconds of inactivity is likely related to a client-side configuration rather than a server-side setting, since your coworkers are not experiencing the same problem.

To address this issue, you can try the following solutions:

  1. Enable keepalives on your SSH client: If you're using PuTTY, go to the Connection page of the PuTTY Configuration and set "Seconds between keepalives" to 59 seconds. This will send a small packet every 59 seconds to keep the connection alive.

  2. If you're using a standard OpenSSH client, you can add the following lines to your ~/.ssh/config file or include them in your SSH command:

    ServerAliveInterval 59 ServerAliveCountMax 3

    This will send a packet every 59 seconds and allow up to 3 missed responses before disconnecting.

  3. If enabling keepalives doesn't resolve the issue, you can try disabling Nagle's algorithm in your SSH client configuration. In PuTTY, this option is also found on the Connection page of the PuTTY Configuration.

  4. Check your local firewall or security software to ensure it's not interfering with your SSH connection.

  5. Verify that your network connection is stable and not dropping packets.

If none of these solutions work, you may want to compare your SSH client version and configuration with those of your coworkers to identify any differences that could be causing the issue.

Remember that EC2 Instance Connect sessions typically last for an hour, so the 60-second disconnect you're experiencing is likely not related to the EC2 instance itself but rather to your local configuration or network conditions.

If the problem persists, you may want to consult with your IT department or AWS support for further assistance in troubleshooting your specific setup.

Sources
Troubleshoot issues connecting to your Amazon EC2 Linux instance - Amazon Elastic Compute Cloud
Disconnect from the EC2 Serial Console - Amazon Elastic Compute Cloud
Connect to your Linux instance using EC2 Instance Connect - Amazon Elastic Compute Cloud

answered 2 years ago

EXPERT

reviewed 2 years ago

  • I've check the firewall and it seems normal. The difference that I get between my coworkers is the openSSH version

    Mine: OpenSSH_8.9p1 Ubuntu-3ubuntu0.10, OpenSSL 3.0.2 15 Mar 2022

    Theirs: OpenSSH_8.2p1 Ubuntu-4ubuntu0.11, OpenSSL 1.1.1f 31 Mar 2020

  • I've accessed a Raspberry PI inside my network, and the connection didn't drop. Is this problem still related to my pc, openssh version somehow?

  • Remember that EC2 Instance Connect sessions typically last for an hour ---> How to increase this limit? I get Websocket Closure Reason: Connection exceeded session timeout after an hour and it kicks me out.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.