I SSH from one Linux host to another Linux host that I don't administer. Its /etc/ssh/sshd_config is apparently configured to auto-logout after an interval of inactivity that is too brief for my taste (How do I enable auto-logout of Interactive ssh logins after one hour).

Is there any way to keep my SSH session alive, perhaps by sending or receiving a newline character every two minutes?

Workarounds like while true { echo ' '; sleep 120 } were common in the days of dialup modems).

FWIW, Windows' PuTTY isn't involved at all.


Is it bash's TMOUT, or ssh? If it's TMOUT, there are a couple options listed here.





Add this line to $HOME/.ssh/config on the SSH client side:

ServerAliveInterval 60

Adjust the interval (60) to whatever works for your situation. See the man pages for details.

I hope it helps.


In bash: while sleep 120; do printf '\33[0n'; done.

Edit: This emits an invisible string every two minutes. Those characters sent to the terminal are enough to fool whatever is looking for inactivity on the ssh session.

To stop this and get a bash prompt again, just hit Ctrl+C.

  • Thanks for closing the loop on your question. Could you add a sentence or two to explain what this does?
    – fixer1234
    May 24 '17 at 16:52

Try to edit your sshd_config file.  In my case it was on /etc/ssh/sshd_config.


ClientAliveInterval 300
ClientAliveCountMax 0


ClientAliveInterval 6000
ClientAliveCountMax 3

Don’t forget

service sshd restart
  • This answers a different question. The original question is about what to do when you can't change the target host's configuration. Oct 4 '17 at 16:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.