How to affect ssh parameters on ssh-agent like keep alive

Recently went through a problem where the ssh connection was dying in a weird way. As in says it was connected but all traffic was hanging.

The way we fixed this at the ssh level was by playing around with the keep-alive parameters. How do I affect/change these for the ssh-slave connection?

Hi Michael,

As a reminder, the term “slave” to refer to an agent has been deprecated since 2016. Please refer to On Jenkins Terminology Updates for more details. We request you update your post.
You could configure the SSH keep-alive parameters for a Jenkins agent using SSH by setting the appropriate values in the ~/.ssh/config file on the Jenkins agent machine.

Here is an example of how to set the SSH keep-alive parameters in the ~/.ssh/config file:

Host *
    ServerAliveInterval 60
    ServerAliveCountMax 3

In this example, the ServerAliveInterval parameter is set to 60 seconds, which means that the SSH client will send a keep-alive message to the server every 60 seconds. The ServerAliveCountMax parameter is set to 3, which means that if the server does not respond to the keep-alive messages for 3 consecutive times, the client will assume that the connection is no longer alive and will terminate it.

You can adjust these values according to your needs. Just make sure to restart the Jenkins agent after making any changes to the ~/.ssh/config file.