Skip to content

Instantly share code, notes, and snippets.

@sheikhnavezz
Created March 9, 2024 19:03
Show Gist options
  • Save sheikhnavezz/8af88abdc9781ffc7d964e6e1ecda8af to your computer and use it in GitHub Desktop.
Save sheikhnavezz/8af88abdc9781ffc7d964e6e1ecda8af to your computer and use it in GitHub Desktop.
This file contains the solution for ssh getting inactive after few minutes

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..! 👨‍💻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment