- Newest
- Most votes
- Most comments
The issue you're experiencing with EC2 Instance Connect is related to the default session timeout. EC2 Instance Connect sessions typically last for one hour, after which you're automatically disconnected even if you're actively using the session.
Unfortunately, this one-hour session limit for EC2 Instance Connect is a fixed value and cannot be extended. This is different from the idle timeout that can be configured in some other AWS services.
To work around this limitation, you have a few options:
-
Use a standard SSH client instead of EC2 Instance Connect. With a standard SSH client, you can configure keepalives to maintain your connection for longer periods.
-
If you need to use EC2 Instance Connect, you'll need to reconnect after the one-hour timeout. You might want to consider setting up scripts or processes that can handle reconnection automatically.
-
For longer sessions, consider using AWS Systems Manager Session Manager which may offer different timeout configurations.
If you're using a standard SSH client and experiencing disconnections, you can add the following to your SSH configuration:
ServerAliveInterval 59
ServerAliveCountMax 3
This will send a packet every 59 seconds to keep the connection alive and allow up to 3 missed responses before disconnecting.
Sources
EC2 ssh closes my connection, but not for others | AWS re:Post
Relevant content
- asked 9 months ago
- asked 3 years ago
- AWS OFFICIALUpdated 3 months ago
