Select Language:
If you’re using EC2 Instance Connect and find that your session keeps disconnecting after about an hour, you’re experiencing the default session timeout. These sessions are designed to last for one hour, and once that time is up, you’ll be disconnected automatically—even if you’re actively working. Unfortunately, this one-hour limit is fixed and can’t be changed, which is different from some other AWS services where you can adjust idle timeouts.
To solve this problem, here are some practical options you can try:
First, consider switching to a traditional SSH client. Unlike EC2 Instance Connect, most SSH clients let you configure keepalive settings. This helps keep your connection alive longer by periodically sending signals between your client and the server. You can do this by adding a few lines to your SSH configuration file:
ServerAliveInterval 59
ServerAliveCountMax 3
This setup sends a small packet every 59 seconds, and if three packets go unanswered, the connection will be closed. It’s an effective way to prevent disconnections caused by network issues or server timeouts.
If you prefer to stick with EC2 Instance Connect, you’ll need to reconnect once the session ends. To make this process smoother, consider automating the reconnection process using scripts that detect session expiration and reconnect automatically.
For longer-term solutions, think about using AWS Systems Manager Session Manager. It offers more flexible session timeout options and can provide persistent shell access without the one-hour limit.
By using these methods, you can maintain longer sessions and work more efficiently without frequent reconnects.





