5

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.

Giacomo1968
  • 58,727

4 Answers4

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.

Giacomo1968
  • 58,727
fnds
  • 86
2

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.

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