# How to keep ssh sessions alive

**URL:** <https://linux-tips.com/t/how-to-keep-ssh-sessions-alive/255>\
**Category:** Network\
**Created:** [June 18, 2015, 12:14pm UTC](https://linux-tips.com/t/how-to-keep-ssh-sessions-alive/255 "2015-06-18T12:14:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![demirten](https://linux-tips.com/user_avatar/linux-tips.com/demirten/32/64_2.png) [@demirten](https://linux-tips.com/u/demirten)\
**Post date:** [June 18, 2015, 12:14pm UTC](https://linux-tips.com/t/how-to-keep-ssh-sessions-alive/255/1 "2015-06-18T12:14:44Z")

</div>

There are two ways to keep ssh sessions alive.

**Client-Side:**

On the client side, it is possible to configure your ssh client to send keep alive packets to server. It can be configured by system wide through `/etc/ssh/ssh_config` or user specific `~/.ssh/config` files.

```
Host *
ServerAliveInterval 60
ServerAliveCountMax 3

```

With above configuration, your ssh client will send keep alive packets to server on every 60 seconds and if it couldn’t receive any response for sequential 3 keep alive packets, connection will be closed.

**Server-Side:**

It is also possible to change ssh keep alive packets behaviour on the server side. By this way, you can keep your clients’ sessions alive without need to make special configuration on the client side.

Append following lines to your `/etc/ssh/sshd_config` file:

```
ClientAliveInterval 180
ClientAliveCountMax 2

```

and restart your ssh service:

```
$ sudo service ssh restart

```

After this configuration your sshd server will start to send keep alive packets to their clients on every 180 seconds and if it couldn’t receive answer on 2 sequential packets, client connection will be closed.
