Way to prevent SSH sessions from timing out?

I SSH into my server from an iTerm session. I've noticed that after a certain amount of time, my session times out. This means I have to close that iTerm window which messes up my iTerm window configuration and I have to set them all up again. Is there some way I can prevent my session from timing me out or at least set it to a longer time interval like perhaps a couple of hours?

Thanks.

2 Replies

Hey,

There's 2 suggestions, and two ways to adjust timeout. My first suggestion is to not use SSH in the first place but a tool called MoSH. I use it myself and works great for this situation, changing IPs, high-latency connections, etc.

Now if you don't want to install anything else, you can adjust timeouts both server side and client side. Server side, in /etc/ssh/sshd_config you should make sure the following is set:

TCPKeepAlive yes
ClientAliveCountMax 99999
ClientAliveInterval 30

Client side, you should have the following set in ~/.ssh/config:

ServerAliveInterval 100

For both ServerAliveInterval or ClientAliveInterval, this is telling SSH how often is should poll the connection, preventing the connection from timing out. ClientAliveCountMax is how many times to poll before considering the client dead.

I hope that helps.

Thanks. I'll give this a try. It's probably also necessary to restart SSH on the server with: sudo service ssh restart

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct