SSH Session Controlled


Remember ssh. Yes same ssh using which you restarted or shutdown your classmate machines during your RHCE Training.

Now, Encounter this.

You are doing some important and lengthy task on some Linux Server using ssh connection.

You are not bothered about physical security of the machine from which you had established the ssh connection.

Now went out for a cup of tea / coffee.

And .. you must have experienced that after a certain amount of time of inactivity the ssh or if you leave an SSH connection sitting open for too long but don’t actually put any data through it,
you may find that it drops out. This can be irritating.

But can be solved, using the ServerAliveInterval option of ssh.

Just create a file under – ~/.ssh/config

and write these lines inside it –

Host *
Protocol 2
ServerAliveInterval 40

— save and exit.

First line says that this setting implies for all hosts.
Second line says that its applicable only for ssh v2 connections.
Third line will keep on sending a packet to the server after every 40 seconds of inactivity, thus making your connection active.

Feel free to change the 40 seconds of interval to your choice.

Here is a illustration from my machine.

Enjoy and Share.

control ssh sessions in Linux

control ssh sessions in Linux