# Lost connection to server using Putty (due to packet loss)



## Aknot (Aug 26, 2021)

Hello,

I'm using Putty to connect to my FreeBSD server.
Several times a day, my connection drops due to packet loss (ISP capacity problems).

They are very short, but enough to disconnect my Putty session.
This is very annoying, and I wonder if there is something we can do in FreeBSD, increase timeout or change keep alive somewhere?

We have made the appropriate changes in the Putty client, but that doesn't do the trick.

Thank you,


----------



## Emrion (Aug 26, 2021)

Try to set *TCPKeepAlive* to no: sshd_config(5)

But beware:


> if TCP keepalives are not sent, sessions may hang indefinitely on
> the server, leaving "ghost" users and consuming server resources.


----------



## covacat (Aug 26, 2021)

also use screen(1) for your interactive sessions


----------



## Vull (Aug 26, 2021)

Haven't used PuTTY or PowerTerm for years but used to run a keepalive script on idle terminal sessions to keep them from timing out. I still use one now and then for ssh sessions, and it works. Prints one period per minute on the terminal / one line of text per hour.

```
#!/bin/sh
x=0; y=0; z=0
while :;do
  sleep 60
  echo -n "."
  x=$((x+1))
  if [ $x -eq 5 ];then x=0; echo -n " ";fi
  y=$((y+1))
  z=$((z+1))
  if [ $y -eq 60 ];then
    y=0; z=0; echo
  elif [ $z -eq 10 ];then
    z=0; echo -n " "
  fi
done
```


----------



## mark_j (Aug 26, 2021)

covacat said:


> also use screen(1) for your interactive sessions


This is great advice. Because the disconnects are out of your control, at least you can re-establish what you were doing using screen or tmux.


----------



## Argentum (Aug 26, 2021)

Aknot said:


> I'm using Putty to connect to my FreeBSD server.
> Several times a day, my connection drops due to packet loss (ISP capacity problems).
> 
> They are very short, but enough to disconnect my Putty session.
> ...


Do not know, if this helps you, bu I am always using sysutils/screen. Especially on servers. So, when the ssh connection is terminated, all the shell sessions remain open. I can always log in again and reconnect.


----------



## hardworkingnewbie (Aug 26, 2021)

Why don't you use Mosh instead (net/mosh)? It's been designed to recover automatically from connection drops. It even reconnects automatically in case your IP address has changed after a disconnect.


----------



## diizzy (Aug 28, 2021)

mosh (and possibly tmux) is probably your best bet


----------



## Aknot (Sep 11, 2021)

Thank you everyone, testing net/mosh right now and it seems to be working just great


----------



## hardworkingnewbie (Sep 11, 2021)

Glad to hear that it feeds your need!


----------

