Score:0

How to prevent SSH timeout of idle sessions?

cn flag

I'm using iterm2 to SSH from a Mac to an RHEL server. ServerAliveInterval is set to 60 in the client SSH config and TCPKeepAlive is set to 'yes' in the server sshd config. However, idle sessions always timeout after some period (I have not timed it). Running sessions, e.g. a long-running process or a tail will stay alive indefinitely. Is there some way to keep idle sessions alive using some combination of server, client, and iterm2 settings that I have been unable to find?

jm flag
Do you happen to have `TMOUT` set in your environment?
zenzic avatar
cn flag
Oh, wow, good call. It is set to 900, which matches the 15 minute timeout I am seeing. Is that a per user (user I am ssh-ing to) setting? And it looks like 0 is never?
zenzic avatar
cn flag
Thanks @doneal24, between that and the config changes suggested below, things are behaving much better. Thanks for the response!
Score:0
fr flag

I am using ServerAliveInterval on a client side together with ClientAliveInterval on a server side for that purpose and I haven't seen drops (except the case of total loss of connectivity) in years.

I don't set TCPKeepALive but I believe it is on by default (but I doubt it is ever generated as my above settings are in a range which likely prevents it).

For the case when the connection drops/hangs I suggest using tmux or screen and run a program inside it. You will be able to resume the session on subsequent connection. This of course only works for command line / text applications, X forwarding will break.

EDIT:

I am using:

ClientAliveInterval 60
ClientAliveCountMax 5

and

ServerAliveInterval 30
ServerAliveCountMax 10

I probably should change the latter to match the former.

zenzic avatar
cn flag
`ClientAliveInterval` is set to 300. I think it is timing out longer than 5 minutes, but I will lower that to 60 to see if it helps. Thanks for the suggestion. I do use screen and/or tmux (can't decide which I prefer) for network drops, but my immediate problem is that I just hate having to restart idle sessions every time I go to do something.
zenzic avatar
cn flag
I added both your changes and set TMOUT to 0 as suggested by @doneal24 and it has not timed me out after 30+ minutes. Thanks!
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.