SSH session freezes after some time

5,728

Solution 1

Send every 15 seconds (e.g.) an alive packet to keep connection up:

ssh user@server -o ServerAliveInterval=15

Solution 2

In my case problem was in large MTU size. You can change MTU on router if you using NAT, but I change MTU on server:

sudo /sbin/ifconfig eth0 mtu 1036
sudo /etc/init.d/networking restart

On Windows you can also increase this key:

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters]
"TcpMaxDataRetransmissions"=dword:00000010
Share:
5,728

Related videos on Youtube

Debashis
Author by

Debashis

Updated on September 18, 2022

Comments

  • Debashis
    Debashis over 1 year

    The ssh session freezes if I don't work on the terminal for few minutes(~20 to 30 minutes). Is there any command to cope with this? In fact, in my case, I am working on two servers. At first, I need to go to the access server than to the work server. This work server freezes after some time.

    Thanks

  • Debashis
    Debashis about 5 years
    Thank You! It works. Is it also useful to write this in the config file in the .ssh? So that each time doesn't need to write the command.
  • Cyrus
    Cyrus about 5 years
    Yes, you can also write it in ~/.ssh/config