• Skip to primary navigation
  • Skip to content

GitopsCentral

  • Home
  • Courses
  • Roadmap
  • About
  • Log In
  • Sign Up

Increase SSH connection timeout

December 4, 2022 by shaik zillani

In this blog we are going to see how to increase session timeout in openssh server.

The can be done in two ways, you can either set this on server side or you can set this on client side. Let’s check both ways.

Definition

ServerAliveInterval: Number of seconds that the client will wait before sending a null packet to the server (to keep the connection alive).

ClientAliveInterval: Number of seconds that the server will wait before sending a null packet to the client (to keep the connection alive).

On Server Side

On the Server side, update client timeout. Increase Client interval in sshd_config,

vi /etc/ssh/sshd_config

Update following parameters & restart the sshd server, (set for 3600 x 2 = 2 hours)

ClientAliveInterval 3600 
ClientAliveCountMax 2

Restart sshd server,

systemctl restart sshd

On the Client side

Openssh client

If you are using openssh as client, then on the client side, increase serveralive interval in the config below,

vi /etc/ssh/ssh_config
or 
vi /root/.ssh/config

Add the below lines under the config & save

HOST *
  ServerAliveInterval 60
  ServerAliveCountMax 2

Above configuration will poke server every 60 seconds if its alive or not. Will retry 2 times.

Putty

If you are using Putty as your client, then, we need to set a time interval (60 seconds in below example) in order to keep the session alive. This will keep the session alive by poking it every 60 seconds.

linux openssh,  ssh

© Copyright 2016-2025 gitopscentral · All Rights Reserved ·