If your SSH connection to an AWS instance is getting disconnected every 5 minutes of idle time, it is likely due to the default timeout settings of the AWS server.
The server is configured to drop your connection afteronly 60 seconds of inactivity .
To avoid this, you can set a keep-alive option in your
~/.ssh/config
file on the client’s home directory. Add the following line to the file:
ServerAliveInterval 50
This option will ping the server every 50 seconds and keep you connected indefinitely.
[Please note that this setting is on the client side and not on the AWS server.]
If you are still facing issues, you can try adding
“client-alive”
directive to the instance’s SSH-serverconfiguration file. Remote into your EC2 instance and run the following command:
echo 'ClientAliveInterval 60' | sudo tee --append /etc/ssh/sshd_config
This will add a directive that sends a message through the encrypted channel to request a response from theclient every 60 seconds .
I hope this helps..! 👨💻