how to keep an ssh connection from closing?

12,786

If you can't change the server setting, you should start your ssh by specifying frequent keep-alive signals to allow your command to complete. E.g.

ssh -o ServerAliveInterval=20 [email protected]

should issue an "alive" signal every 20 seconds towards the server, so that it keep the connection alive

Share:
12,786
Khalood Kj
Author by

Khalood Kj

Updated on June 04, 2022

Comments

  • Khalood Kj
    Khalood Kj almost 2 years

    I'm trying to run a command that might take 1+ hours and I've tried adding

    while sleep 300; do echo "1"; done
    

    so that it doesn't disconnect me for being idle and it worked.

    But it still disconnects after sometimes for another reason it says Connection to *.*.*.* closed by remote host.

    I guess its just a default time limit or something I don't really know?

    Is there a way to increase that time or just make it never disconnects?

    If not is there a way to keep that command running even after closing the ssh connection ?