How to prevent SSH from disconnecting sessions

My ssh connection and session to a remote AWS server gets disconnected by that instance after 10 minutes of no user input or activity. How do I prevent SSH from disconnecting when idle for a while? I am on Fedora Linux 36 desktop and EC2 is RHEL 8 if that helps.

Edit the ~/.ssh/config and append the following

ServerAliveInterval 10
ServerAliveCountMax 3

Save and close the file. Now try it out. See the following tutorials more info:

And:

And:

How to prevent SSH from disconnecting if it’s been idle for a while using the ssh CLI option only

If you do not wish to edit the ~/.ssh/config file, then pass the following options:

ssh -o "ServerAliveInterval 10" -o "ServerAliveCountMax 3"  ec2-user@ec2-server-ip-hostnme-here

For more info read the following manual pages using the man command or help command:

man ssh
man ssh_config
1 Like