Tuesday, April 9, 2013

How to Keep an SSH Connection Alive in Linux

To prevent your SSH session from timing out, you can configure the SSH server settings to keep the session alive. Here's how:

  1. Edit the SSH server configuration file:

    sudo vi /etc/ssh/sshd_config
  2. Add or modify the following lines to keep the SSH connection alive:

    ClientAliveInterval 60 ClientAliveCountMax 3
    • ClientAliveInterval 60: This sets the server to send a message to the client every 60 seconds to keep the connection alive.
    • ClientAliveCountMax 3: This specifies that if the server doesn't receive a response from the client after 3 consecutive keep-alive messages, the server will disconnect the session.
  3. Restart the SSH service to apply the changes:

    sudo service sshd restart