I have a Ubuntu 12.04 server I bought, if I connect with putty using ssh and a sudoer user putty gets disconnected by the server after some time if I am idle

How do I configure Ubuntu to keep this connection alive indefinitely?

5 Answers 5


If you go to your putty settings -> Connection and set the value of "Seconds between keepalives" to 30 seconds this should solve your problem.

PuTTY Configuration

  • 3
    ?????? "0 to turn off" or 30 to turn off????????? I think he must put 0 instead of 30!
    – kokbira
    Feb 19, 2018 at 11:42
  • 3
    No, it's the time between keepalives. If you set it to 0, no keepalives are sent but you want putty to send keepalives to keep the connection alive.
    – das Keks
    Feb 19, 2018 at 11:46
  • 4
    Why 30 seconds? He said never timeout so it should be "9999999999999" ?
    – NoName
    Mar 5, 2019 at 18:46
  • 6
    @NoName Because the setting is for the "keepalive interval". That means it sends a "ping" every 30 seconds to prevent the connection from timing out.
    – das Keks
    Mar 7, 2019 at 13:54
  • 1
    For me it worked without the tcp checkbox. Because the tcp connection is used to send the "null packet" there may be no need for an additional tcp keepalive. If idle tcp connections are killed by a router or firewall within a few seconds this checkbox could help (or set the seconds between keepalives to 5 or even 1).
    – das Keks
    Apr 10, 2019 at 10:48

Go to PuTTy options --> Connection

  1. Change the default value for "Seconds between keepalives(0s to turn off)"
    • change it from 0s to 60s (1 minutes) --This varies...reduce if 1 minutes doesn't help
  2. Check the "Enable TCP_keepalives (SO_KEEPALIVE option)" check box.
  3. Finally save setting for session

In addition to the answer from "das Keks" there is at least one other aspect that can affect this behavior. Bash (usually the default shell on Ubuntu) has a value TMOUT which governs (decimal value in seconds) after which time an idle shell session will time out and the user will be logged out, leading to a disconnect in an SSH session.

In addition I would strongly recommend that you do something else entirely. Set up byobu (or even just tmux alone as it's superior to GNU screen) and always log in and attach to a preexisting session (that's GNU screen and tmux terminology). This way even if you get forcibly disconnected - let's face it, a power outage or network interruption can always happen - you can always resume your work where you left. And that works across different machines. So you can connect to the same session from another machine (e.g. from home). The possibilities are manifold and it's a true productivity booster. And not to forget, terminal multiplexers overcome one of the big disadvantages of PuTTY: no tabbed interface. Now you get "tabs" in the form of windows and panes inside GNU screen and tmux.

apt-get install tmux
apt-get install byobu

Byobu is a nice frontend to both terminal multiplexers, but tmux is so comfortable that in my opinion it obsoletes byobu to a large extent. So my recommendation would be tmux.

Also search for "dotfiles", in particular tmux.conf and .tmux.conf on the web for many good customizations to get you started.


I keep my PuTTY sessions alive by monitoring the cron logs

tail -f /var/log/cron

I want the PuTTY session alive because I'm proxying through socks.


The 30 seconds timeout never worked for me so I tried playing with a bit and came up with a solution by increasing the timeout to 240(4 mins), now it works like a charm

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .