How To Keep An SSH Connection Alive in Linux
By default, many Linux configurations automatically close SSH sessions after a certain amount of inactivity.
You can easily change this setting on your system by editing the sshd configuration file.
Of course, before doing so, you should consider the security implications of keeping SSH sessions active. Setting your server to keep connections alive may present a security risk, as users may inadvertently leave connections active & walk away from their computer. Worse, they may purposely leave them active, not realizing the security risk.
Since I do all of my computing from steel-reinforced steel bunker buried deep in the ground and secured by armed guards 24×7, I’m not worried about the security implications of leaving sessions active.
To set your Ubuntu, Red Hat, or CentOS server to keep ssh connections alive, you need to edit the /etc/ssh/sshd_config file and edit the TCPKeepAlive and ClientAliveInterval lines. Uncomment these lines if commented out, and make the following changes:
vi /etc/ssh/sshd_config
TCPKeepAlive yes
ClientAliveInterval 300
After doing so, restart the sshd daemon.
/etc/init.d/sshd restart


February 8th, 2011 at 8:03 pm
Hi Eddie,
I sure appreciate your help on this issue. I am trying to pull a system backup down to a local machine on a slow DSL connection.
Thank you, Sharon