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