1

When I use a Linux server on my house and I access it from the Internet, I can keep the terminal window open with an SSH connection for as long as I want. However, when I use a Linux server on cloud services like AWS or Oracle cloud, my terminal always freezes after some minutes I leave it idle. That bothers me a lot because many times I'm still researching about the subject that I'm doing and then my SSH connection with the cloud is frozen when I come back. That results in me having to close the terminal and reopen the connection with a new one, and then reopening everything again, so I end up spending a lot of time on this during the day. I've looked in the file /etc/ssh/sshd_config if I could find anything related to connection timeouts to understand why it happens but I didn't find anything.

Also, I've found this question here on Unix Exchange that seems related. According to the accepted answer, if I use the parameter -o TCPKeepAlive=true while connecting with ssh this problem would be solved. In my case, it didn't solve the problem at all, the connection still freezes after some time idle, the command that I used was something like the following:

ssh -i myprivatekey -o TCPKeepAlive=true user@serverip

Is there any configuration I can change on my computer or the server to solve this problem? How can I make an SSH connection stop freezing after being idle for a while?

1
  • You have to find out first it if is an actual ssh timeout or, for example, a firewall somewhere along the way sending an RST after some time (could it be upstream or downstream). Leave a process with constant output, something like `while sleep 5; do date; done'. Does it stop too? Jan 8 at 19:25
2

Try passing -o ServerAliveInterval=20 which would regularly send some poking data as part of the ssh protocol and may help with your issue.

Also you may want to use the tmux or screen terminal multiplexers in your ssh session, so it would just be a matter of reattaching your session when you reconnect instead of having to restart everything.

2
  • I've tested passing -o ServerAliveInterval=20 to connect on an Oracle cloud server but it still freezes after some time ;/... But thanks for the tmux and screen suggestions, I already use them for background processes sometimes but I didn't think of using them in this case...
    – raylight
    Jan 8 at 8:00
  • @raylight, try running ssh is a few -v options (or enter ~v a few times from within your ssh session) to see if that can give you any clue. Jan 8 at 8:23

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.