Get your server issues fixed by our experts for a price starting at just 25 USD/Hour. Click here to register and open a ticket with us now!

Author Topic: How to prevent SSH from disconnecting sessions  (Read 1273 times)

0 Members and 1 Guest are viewing this topic.

akhilt

  • Guest
How to prevent SSH from disconnecting sessions
« on: March 24, 2018, 04:31:00 am »
If you work with SSH, you already know that after afew minutes of inactivity, a session would be closed automatically, for security reasons. You can change this behaviour in your GNU/Linux configuration. The following steps will help you to do this.

How to stop SSH from disconnecting

The following steps needs to be performed in your SSH client, not in the remote server.

First of all, open your text editor and modify your current user config file, which is located at:

Code: [Select]
~/.ssh/config
Add the following lines:

Code: [Select]
Host *
 ServerAliveInterval 60

Ensure that the second line will start with a space.

The first line, tells SSH to apply this configuration for all remote hosts. Of course, you can specify just one of them, changing ‘*’ with the desired host.

After you did this, you need to apply the above settings:

Code: [Select]
sudo source ~/.ssh/config
To apply this setting globally, add or modify the following line in /etc/ssh/ssh_config file.

Code: [Select]
ServerAliveInterval 60

Save and close the file.

In this way, your SSH session will not be closed for inactivity.


Conclusion


 Changing the behaviour of programs like SSH must be done only if you know exactly what you want, and after being sure that this will not put you in some problem.