Aside from the well known Client side solution, that unfortunately doesn't prevent the Server from closing the connection after a certain period of inactivity, that is including something on the lines of
ServerAliveInterval 30
ServerAliveCountMax 240000000
in the
/home/username/.ssh/config
file and restarting sudo systemctl restart ssh
, I've found that the following works wonderfully. By using xdotool
sudo apt update
sudo apt install xdotool
one can write a no_more_broken_pipes.sh
file that contains something on the lines of
NBP() {
while true
do
sleep 10
xdotool key Return
done
}
When ran, that is
source no_more_broken_pipes.sh
NBP
it will press Return every ten seconds, regardless of what you are doing, until you abort it with ctrl+c
.
As long as you are focused on the right terminal, the server will receive inputs every ten seconds (sleep 10
), so the connection won't be terminated, even if you go on vacation. If using the return key is not a good idea, the xev
tool will help determine what to write on the command so that a safer key is pressed.
Cautionary tale
While doing this, you should also prevent any pop-up window (of any kind) to appear. I'm including log-in screens (such as i3lock
), available update messages, whatnots. What works incredibly well for me, as long as just one terminal is involved, is the full screen of i3
(usually Super_L+f
): it automatically prevents (so far it has been this way for me) the focus on new windows.
screen
correctly, and the fact that editing the config file gives no guarantees, this option (in my answer) looks quite solid