4

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.

3

4 Answers 4

3

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

https://stackoverflow.com/questions/25675598/getting-kicked-out-of-openshift-server-after-a-while/25689720#25689720

Or
https://unix.stackexchange.com/questions/222283/read-only-tmout-variable-workaround-to-disable-automatically-exit-shell-when-t

-Erik

1
3

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.

0

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.

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

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

was:

ClientAliveInterval 300
ClientAliveCountMax 0

to:

ClientAliveInterval 6000
ClientAliveCountMax 3

Don’t forget

service sshd restart
1
  • 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, 2017 at 16:10

You must log in to answer this question.

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