How to prevent “Write Failed: broken pipe” on SSH connection?












249















What can I do to configure SSH on both client and servers to prevent Write Failed: broken pipe errors? It often occurs if you sleep your client computer and resume later.










share|improve this question




















  • 7





    Nothing really. The session was interrupted, and the security of the session was compromised. If you don't put the comp to sleep you can set a keep alive time for the client to shoot a keep alive heart beat to the server, but if the system's going to sleep then there is nothing that can be done.

    – darkdragn
    Apr 28 '12 at 23:44






  • 3





    In this case I'm looking for something that would allow me to re-initiate a broken ssh connection (based probably on the exit code) and restore using screen?

    – sorin
    Apr 30 '12 at 7:11






  • 3





    You people are wrong: I have TWO desktop client machines connecting to the SAME server. One is ubuntu 12.10, Quantal, whose SSH client works well, and keeps the connection for hours. The other is Ubuntu 14.10, Utopic, just aside the other and in a fresh install; after a couple of minutes, it blocks itself with this message. The rest of the network functions in the machine are not interrupted. So no, it's neither a network problem, nor a server problem, but a specific SSH CLIENT software problem, which CAN be solved, opposite to what "darkdragan" dares to say, that "nothing can be done".

    – David L
    Dec 18 '14 at 6:09






  • 2





    And indeed, as I said: people talk too much when they say "nothing can be done", just as @darkdragn dared. I read Aram Kocharyan 's answer, and I applied it: 20 minutes ago... I realized that in my old Quantal Ubuntu 12.10, I had applied that instruction in that file [I just checked], two years ago, and that was the reason of the stability there. I did it here, and in these last 20 minutes, the connection has been stable since then. So please, people: refrain yourselves when daring to think that "nothing can be done", and refrain even more when trying to leave that message to other people.

    – David L
    Dec 18 '14 at 6:34






  • 11





    @DavidL you should read the questions better before ranting. Your problem is not the same as the OP's, who clearly mentions putting the computer to sleep. Which by the way only one of the answers address ("mosh"), and it was posted 2 years after the question. However the other answers do the next best thing, which is proposing solutions to cases that can be solved more easily, like yours. Chill out, don't be so stressed, ranting doesn't do any good around here...

    – msb
    Apr 8 '15 at 21:40
















249















What can I do to configure SSH on both client and servers to prevent Write Failed: broken pipe errors? It often occurs if you sleep your client computer and resume later.










share|improve this question




















  • 7





    Nothing really. The session was interrupted, and the security of the session was compromised. If you don't put the comp to sleep you can set a keep alive time for the client to shoot a keep alive heart beat to the server, but if the system's going to sleep then there is nothing that can be done.

    – darkdragn
    Apr 28 '12 at 23:44






  • 3





    In this case I'm looking for something that would allow me to re-initiate a broken ssh connection (based probably on the exit code) and restore using screen?

    – sorin
    Apr 30 '12 at 7:11






  • 3





    You people are wrong: I have TWO desktop client machines connecting to the SAME server. One is ubuntu 12.10, Quantal, whose SSH client works well, and keeps the connection for hours. The other is Ubuntu 14.10, Utopic, just aside the other and in a fresh install; after a couple of minutes, it blocks itself with this message. The rest of the network functions in the machine are not interrupted. So no, it's neither a network problem, nor a server problem, but a specific SSH CLIENT software problem, which CAN be solved, opposite to what "darkdragan" dares to say, that "nothing can be done".

    – David L
    Dec 18 '14 at 6:09






  • 2





    And indeed, as I said: people talk too much when they say "nothing can be done", just as @darkdragn dared. I read Aram Kocharyan 's answer, and I applied it: 20 minutes ago... I realized that in my old Quantal Ubuntu 12.10, I had applied that instruction in that file [I just checked], two years ago, and that was the reason of the stability there. I did it here, and in these last 20 minutes, the connection has been stable since then. So please, people: refrain yourselves when daring to think that "nothing can be done", and refrain even more when trying to leave that message to other people.

    – David L
    Dec 18 '14 at 6:34






  • 11





    @DavidL you should read the questions better before ranting. Your problem is not the same as the OP's, who clearly mentions putting the computer to sleep. Which by the way only one of the answers address ("mosh"), and it was posted 2 years after the question. However the other answers do the next best thing, which is proposing solutions to cases that can be solved more easily, like yours. Chill out, don't be so stressed, ranting doesn't do any good around here...

    – msb
    Apr 8 '15 at 21:40














249












249








249


103






What can I do to configure SSH on both client and servers to prevent Write Failed: broken pipe errors? It often occurs if you sleep your client computer and resume later.










share|improve this question
















What can I do to configure SSH on both client and servers to prevent Write Failed: broken pipe errors? It often occurs if you sleep your client computer and resume later.







ssh






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 25 '15 at 15:50









LiveWireBT

21.4k1872154




21.4k1872154










asked Apr 28 '12 at 23:36









sorinsorin

3,866133851




3,866133851








  • 7





    Nothing really. The session was interrupted, and the security of the session was compromised. If you don't put the comp to sleep you can set a keep alive time for the client to shoot a keep alive heart beat to the server, but if the system's going to sleep then there is nothing that can be done.

    – darkdragn
    Apr 28 '12 at 23:44






  • 3





    In this case I'm looking for something that would allow me to re-initiate a broken ssh connection (based probably on the exit code) and restore using screen?

    – sorin
    Apr 30 '12 at 7:11






  • 3





    You people are wrong: I have TWO desktop client machines connecting to the SAME server. One is ubuntu 12.10, Quantal, whose SSH client works well, and keeps the connection for hours. The other is Ubuntu 14.10, Utopic, just aside the other and in a fresh install; after a couple of minutes, it blocks itself with this message. The rest of the network functions in the machine are not interrupted. So no, it's neither a network problem, nor a server problem, but a specific SSH CLIENT software problem, which CAN be solved, opposite to what "darkdragan" dares to say, that "nothing can be done".

    – David L
    Dec 18 '14 at 6:09






  • 2





    And indeed, as I said: people talk too much when they say "nothing can be done", just as @darkdragn dared. I read Aram Kocharyan 's answer, and I applied it: 20 minutes ago... I realized that in my old Quantal Ubuntu 12.10, I had applied that instruction in that file [I just checked], two years ago, and that was the reason of the stability there. I did it here, and in these last 20 minutes, the connection has been stable since then. So please, people: refrain yourselves when daring to think that "nothing can be done", and refrain even more when trying to leave that message to other people.

    – David L
    Dec 18 '14 at 6:34






  • 11





    @DavidL you should read the questions better before ranting. Your problem is not the same as the OP's, who clearly mentions putting the computer to sleep. Which by the way only one of the answers address ("mosh"), and it was posted 2 years after the question. However the other answers do the next best thing, which is proposing solutions to cases that can be solved more easily, like yours. Chill out, don't be so stressed, ranting doesn't do any good around here...

    – msb
    Apr 8 '15 at 21:40














  • 7





    Nothing really. The session was interrupted, and the security of the session was compromised. If you don't put the comp to sleep you can set a keep alive time for the client to shoot a keep alive heart beat to the server, but if the system's going to sleep then there is nothing that can be done.

    – darkdragn
    Apr 28 '12 at 23:44






  • 3





    In this case I'm looking for something that would allow me to re-initiate a broken ssh connection (based probably on the exit code) and restore using screen?

    – sorin
    Apr 30 '12 at 7:11






  • 3





    You people are wrong: I have TWO desktop client machines connecting to the SAME server. One is ubuntu 12.10, Quantal, whose SSH client works well, and keeps the connection for hours. The other is Ubuntu 14.10, Utopic, just aside the other and in a fresh install; after a couple of minutes, it blocks itself with this message. The rest of the network functions in the machine are not interrupted. So no, it's neither a network problem, nor a server problem, but a specific SSH CLIENT software problem, which CAN be solved, opposite to what "darkdragan" dares to say, that "nothing can be done".

    – David L
    Dec 18 '14 at 6:09






  • 2





    And indeed, as I said: people talk too much when they say "nothing can be done", just as @darkdragn dared. I read Aram Kocharyan 's answer, and I applied it: 20 minutes ago... I realized that in my old Quantal Ubuntu 12.10, I had applied that instruction in that file [I just checked], two years ago, and that was the reason of the stability there. I did it here, and in these last 20 minutes, the connection has been stable since then. So please, people: refrain yourselves when daring to think that "nothing can be done", and refrain even more when trying to leave that message to other people.

    – David L
    Dec 18 '14 at 6:34






  • 11





    @DavidL you should read the questions better before ranting. Your problem is not the same as the OP's, who clearly mentions putting the computer to sleep. Which by the way only one of the answers address ("mosh"), and it was posted 2 years after the question. However the other answers do the next best thing, which is proposing solutions to cases that can be solved more easily, like yours. Chill out, don't be so stressed, ranting doesn't do any good around here...

    – msb
    Apr 8 '15 at 21:40








7




7





Nothing really. The session was interrupted, and the security of the session was compromised. If you don't put the comp to sleep you can set a keep alive time for the client to shoot a keep alive heart beat to the server, but if the system's going to sleep then there is nothing that can be done.

– darkdragn
Apr 28 '12 at 23:44





Nothing really. The session was interrupted, and the security of the session was compromised. If you don't put the comp to sleep you can set a keep alive time for the client to shoot a keep alive heart beat to the server, but if the system's going to sleep then there is nothing that can be done.

– darkdragn
Apr 28 '12 at 23:44




3




3





In this case I'm looking for something that would allow me to re-initiate a broken ssh connection (based probably on the exit code) and restore using screen?

– sorin
Apr 30 '12 at 7:11





In this case I'm looking for something that would allow me to re-initiate a broken ssh connection (based probably on the exit code) and restore using screen?

– sorin
Apr 30 '12 at 7:11




3




3





You people are wrong: I have TWO desktop client machines connecting to the SAME server. One is ubuntu 12.10, Quantal, whose SSH client works well, and keeps the connection for hours. The other is Ubuntu 14.10, Utopic, just aside the other and in a fresh install; after a couple of minutes, it blocks itself with this message. The rest of the network functions in the machine are not interrupted. So no, it's neither a network problem, nor a server problem, but a specific SSH CLIENT software problem, which CAN be solved, opposite to what "darkdragan" dares to say, that "nothing can be done".

– David L
Dec 18 '14 at 6:09





You people are wrong: I have TWO desktop client machines connecting to the SAME server. One is ubuntu 12.10, Quantal, whose SSH client works well, and keeps the connection for hours. The other is Ubuntu 14.10, Utopic, just aside the other and in a fresh install; after a couple of minutes, it blocks itself with this message. The rest of the network functions in the machine are not interrupted. So no, it's neither a network problem, nor a server problem, but a specific SSH CLIENT software problem, which CAN be solved, opposite to what "darkdragan" dares to say, that "nothing can be done".

– David L
Dec 18 '14 at 6:09




2




2





And indeed, as I said: people talk too much when they say "nothing can be done", just as @darkdragn dared. I read Aram Kocharyan 's answer, and I applied it: 20 minutes ago... I realized that in my old Quantal Ubuntu 12.10, I had applied that instruction in that file [I just checked], two years ago, and that was the reason of the stability there. I did it here, and in these last 20 minutes, the connection has been stable since then. So please, people: refrain yourselves when daring to think that "nothing can be done", and refrain even more when trying to leave that message to other people.

– David L
Dec 18 '14 at 6:34





And indeed, as I said: people talk too much when they say "nothing can be done", just as @darkdragn dared. I read Aram Kocharyan 's answer, and I applied it: 20 minutes ago... I realized that in my old Quantal Ubuntu 12.10, I had applied that instruction in that file [I just checked], two years ago, and that was the reason of the stability there. I did it here, and in these last 20 minutes, the connection has been stable since then. So please, people: refrain yourselves when daring to think that "nothing can be done", and refrain even more when trying to leave that message to other people.

– David L
Dec 18 '14 at 6:34




11




11





@DavidL you should read the questions better before ranting. Your problem is not the same as the OP's, who clearly mentions putting the computer to sleep. Which by the way only one of the answers address ("mosh"), and it was posted 2 years after the question. However the other answers do the next best thing, which is proposing solutions to cases that can be solved more easily, like yours. Chill out, don't be so stressed, ranting doesn't do any good around here...

– msb
Apr 8 '15 at 21:40





@DavidL you should read the questions better before ranting. Your problem is not the same as the OP's, who clearly mentions putting the computer to sleep. Which by the way only one of the answers address ("mosh"), and it was posted 2 years after the question. However the other answers do the next best thing, which is proposing solutions to cases that can be solved more easily, like yours. Chill out, don't be so stressed, ranting doesn't do any good around here...

– msb
Apr 8 '15 at 21:40










10 Answers
10






active

oldest

votes


















229














I have tried this in /etc/ssh/ssh_config for Linux and Mac:



Host *
ServerAliveInterval 120


This is how often, in seconds, it should send a keepalive message to the server. If that doesn't work then train a monkey to press enter every two minutes while you work.



You could set either ServerAliveInterval in /etc/ssh/ssh_config of the client machine or ClientAliveInterval in /etc/ssh/sshd_config of the server machine. Try reducing the interval if you are still getting the error.



Configuration for a single user can be set in file ~/.ssh/config both on the server and client side. Make sure the file has correct permissions chmod 644 ~/.ssh/config.






share|improve this answer





















  • 1





    Yeah I do similar and it works quite well for most things.

    – Oli
    Aug 25 '12 at 0:25






  • 3





    I'm not on a Mac, but Ubuntu 12.04 and the file for this operating system also seems to be ~/.ssh/config.

    – H2ONaCl
    Dec 14 '12 at 13:26






  • 5





    OS X 10.8.4 gives an error Bad configuration option: ClientAliveInterval

    – ohho
    Jul 15 '13 at 4:46






  • 3





    I get that same Bad configuration option error on OSX 10.8.4.

    – Nick Heiner
    Jul 18 '13 at 19:57








  • 10





    Generally, you put these two commands into different parts of the system. Only ServerAliveInterval on the OSX client side... and only ClientAliveInterval on the sshd config file...

    – ftrotter
    Oct 23 '13 at 22:56



















78














SSH sessions may break due to numerous and possibly unavoidable reasons.



A useful utility which can be used to mitigate problems caused by this is called screen. Screen is a powerful utility that allows you to control multiple terminals which will stay alive independently of the ssh session. For example, if you run screen in an ssh session you will see a new terminal open and you can use that to run jobs. Lets say your ssh session dies in the process. Running screen -d then screen -r will reopen the last session and you will be able to continue from there. Make sure you read some of the documentation before using it.






share|improve this answer



















  • 4





    This is probably the best answer, I'm not sure why it's not voted up higher. The other "fixes" are helpful in the special case where you would actually care about maintaining an SSH connection, but in most use cases I imagine the real concern is that the intended processes continue to run, regardless of any client/server connection issues whatsoever.

    – Paul McMurdie
    Jun 3 '13 at 17:33






  • 15





    I would also add Tmux as an alternative to screen. I find it more versatile and stable than screen.

    – fridaymeetssunday
    Jan 5 '15 at 15:28






  • 2





    just leaving this here for future reference – you can conveniently run screen -d -r to recover your last session.

    – doplumi
    Nov 21 '16 at 7:41













  • Or simply screen -dr. Or screen -x depending on what you're planning on doing. The point is, one ought to know what all those switches do, so that one can use the appropriate ones and not just blindly follow internet people's suggestions. There's a nice compact summary available here: ss64.com/bash/screen.html

    – flith
    May 28 '18 at 6:27



















42














Client configuration



Try creating the file:



~/.ssh/config


Add the contents:



Host *
ServerAliveInterval 30
ServerAliveCountMax 5


Now ssh to your server and see if your problem is fixed. ClientAliveInterval option is only useful when configuring the ssh server (aka sshd), it does not change a thing on the ssh client side, so don't use it in the above configuration file.



This will send a hello-are-you-there signal to the server if no packets have been received in the preceding 30 seconds (as specified above). However, if the number of consecutive hello-are-you-there signals reach ServerAliveCountMax then ssh will disconnect from the server. This value is defaulting to 3 (so 3*30 = 90 seconds without server activity), increase it if it suits your needs. There are alot more config options to the .ssh/config file and you could read:



Using an SSH Config File



For more information on other options. You may not want to apply this to every server you connect to which this example will. Or restrain it to only a particular server by replacing the line Host * with Host <IP> (replace by an IP address, see ssh_config man page).



Server configuration



Similarly you can tell the server to be gentle with your clients. The configuration file is /etc/ssh/sshd_config.



ClientAliveInterval 20
ClientAliveCountMax 5


You can either deactivate it by setting ClientAliveInterval to 0 or tweak ClientAliveInterval and ClientAliveCountMax to set a maximum ssh client inactivity without responding to the probes. One advantage of this settings over TCPKeepAlive is that the signals are sent through the encrypted channels, so it is less likely to be spoofable.






share|improve this answer


























  • It doesn't work. I am facing the same error again.

    – user997704
    Oct 6 '13 at 4:59






  • 2





    Try it straight from the command line and go lower: ssh -o ServerAliveInterval=5 user@host

    – Matt
    Oct 6 '13 at 10:46













  • Tried that too..doesn't work. I really don't know what is going on with my system

    – user997704
    Nov 15 '13 at 8:39






  • 1





    It's ClientAliveCountMax, NOT ClientAliveMaxCount

    – David G
    Sep 5 '15 at 1:11











  • @DavidG Please edit the answer with your corrections.

    – CivMeierFan
    Feb 3 '16 at 17:35



















22














I'm remotely upgrading an Ubuntu server from lucid to precise and lost the ssh connection in the middle of the upgrade with the message "Write failed. Brocken pipe". ClientAliveInterval and ServerAliveInterval did nothing. The solution is to turn on TCPKeepAlive options in client ssh:



TCPKeepAlive yes


in



/etc/ssh/ssh_config





share|improve this answer

































    19














    For the client, edit your ~/.ssh/config (or /etc/ssh/ssh_config) file as follow:



    Host *
    TCPKeepAlive yes
    ServerAliveInterval 120



    TCPKeepAlive - Specifies whether the system should send TCP keepalive
    messages to the other side. If they are sent, death of the connection
    or crash of one of the machines will be properly noticed. However,
    this means that connections will die if the route is down temporarily,
    and some people find it annoying (The default is 'yes').



    ServerAliveInterval - Sets a timeout interval in seconds after which
    if no data has been received from the server, ssh(1) will send a
    message through the encrypted channel to request a response from the
    server. The default is 0, indicating that these messages will not be
    sent to the server.






    For the server, edit your /etc/ssh/sshd_config as:



    ClientAliveInterval 600
    ClientAliveCountMax 0


    If you want ssh client to exit (timeout) automatically after 10 minutes (600 seconds).




    ClientAliveCountMax – This indicates the total number of checkalive
    message sent by the ssh server without getting any response from the
    ssh client. Default is 3.



    ClientAliveInterval – This indicates the timeout in seconds. After x
    number of seconds, ssh server will send a message to the client asking
    for response. Deafult is 0 (server will not send message to client to
    check.).






    See also: What do the options ServerAliveInterval and ClientAliveInterval in sshd_config do, precisely?






    share|improve this answer


























    • Setting a ServerAliveCountMax higher than the default on the client should also help keep the connection live for slow connections.

      – rippledj
      Oct 1 '18 at 20:29



















    16














    I absolutely love Mosh. I frequently ssh into a server, close my laptop and go to a cafe, open it up and carry on as if nothing changed.




    Mosh (mobile shell)



    Remote terminal application that allows roaming, supports intermittent
    connectivity
    , and provides intelligent local
    echo
    and line editing of user keystrokes.



    Mosh is a replacement for SSH. It's more robust and responsive,
    especially over Wi-Fi, cellular, and long-distance links.



    Mosh is free software, available for GNU/Linux, FreeBSD, Solaris, Mac OS X, and Android.







    share|improve this answer































      5














      For me, I was getting Write failed: Broken pipe even when I was actively typing in vim or at the shell prompt. I couldn't browse the internet locally either for awhile either. (I was connecting remotely to Ubuntu using Terminal.)



      Others in my network stream a lot of video from Netflix and other places. I can't prove it, but I suspect its an ISP or router issue. For example, Verizon and Netflix are pointing fingers at each other for their customer's network problems.



      If you've got a dial-up connection and are streaming video or music with a simultaneous SSH or telnet connection, it's inevitable at some point you'll get a broken pipe message. Upgrading my ISPs broadband package seemed to make my broken connection less frequent.






      share|improve this answer































        3














        I have a script on the remote server that never seems to fails, regardless of the SSH configuration client or server.



        #!/bin/bash
        while true; do date; sleep 10; done;


        Save it to some dummy.sh file and quickly run it before you minimize the window or move away from it. It will keep printing the current time stamp on the server and keeps your connection alive as long as the connection is not dropped by any other reason. When you get back to that terminal, just hit CTRL+C and keep working.






        share|improve this answer



















        • 8





          or simply leave top running

          – Eben Geer
          Dec 19 '13 at 22:43



















        1














        You can add these args every time you invoke ssh: -o ServerAliveInterval=15 -o ServerAliveCountMax=3



        You don't have to edit /etc/ssh/*config files if you do this.



        You can create an bash alias or function or script to make this easy.



        E.g. these bash functions, you can add into your .bashrc, do_ssh is used manually to turn on keepalives. do_ssh_pty is used within scripts to set pty and avoid prompts.



        do_ssh() {
        ssh -o ServerAliveInterval=15 -o ServerAliveCountMax=3 $*
        }

        do_ssh_pty() {
        ssh -tt -o "BatchMode=yes" -o "StrictHostKeyChecking=no" -o ServerAliveInterval=15 -o ServerAliveCountMax=3 $*
        }


        Now do_ssh user@host can be used or do_ssh user@host <args> <command> and keepalives will be active.






        share|improve this answer































          0














          I posted my answer here, as it was not a Ubuntu VM.



          https://unix.stackexchange.com/questions/259225/packet-write-wait-broken-pipe-even-leaving-top-running



          ssh -o IPQoS=throughput user@host





          share|improve this answer































            10 Answers
            10






            active

            oldest

            votes








            10 Answers
            10






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            229














            I have tried this in /etc/ssh/ssh_config for Linux and Mac:



            Host *
            ServerAliveInterval 120


            This is how often, in seconds, it should send a keepalive message to the server. If that doesn't work then train a monkey to press enter every two minutes while you work.



            You could set either ServerAliveInterval in /etc/ssh/ssh_config of the client machine or ClientAliveInterval in /etc/ssh/sshd_config of the server machine. Try reducing the interval if you are still getting the error.



            Configuration for a single user can be set in file ~/.ssh/config both on the server and client side. Make sure the file has correct permissions chmod 644 ~/.ssh/config.






            share|improve this answer





















            • 1





              Yeah I do similar and it works quite well for most things.

              – Oli
              Aug 25 '12 at 0:25






            • 3





              I'm not on a Mac, but Ubuntu 12.04 and the file for this operating system also seems to be ~/.ssh/config.

              – H2ONaCl
              Dec 14 '12 at 13:26






            • 5





              OS X 10.8.4 gives an error Bad configuration option: ClientAliveInterval

              – ohho
              Jul 15 '13 at 4:46






            • 3





              I get that same Bad configuration option error on OSX 10.8.4.

              – Nick Heiner
              Jul 18 '13 at 19:57








            • 10





              Generally, you put these two commands into different parts of the system. Only ServerAliveInterval on the OSX client side... and only ClientAliveInterval on the sshd config file...

              – ftrotter
              Oct 23 '13 at 22:56
















            229














            I have tried this in /etc/ssh/ssh_config for Linux and Mac:



            Host *
            ServerAliveInterval 120


            This is how often, in seconds, it should send a keepalive message to the server. If that doesn't work then train a monkey to press enter every two minutes while you work.



            You could set either ServerAliveInterval in /etc/ssh/ssh_config of the client machine or ClientAliveInterval in /etc/ssh/sshd_config of the server machine. Try reducing the interval if you are still getting the error.



            Configuration for a single user can be set in file ~/.ssh/config both on the server and client side. Make sure the file has correct permissions chmod 644 ~/.ssh/config.






            share|improve this answer





















            • 1





              Yeah I do similar and it works quite well for most things.

              – Oli
              Aug 25 '12 at 0:25






            • 3





              I'm not on a Mac, but Ubuntu 12.04 and the file for this operating system also seems to be ~/.ssh/config.

              – H2ONaCl
              Dec 14 '12 at 13:26






            • 5





              OS X 10.8.4 gives an error Bad configuration option: ClientAliveInterval

              – ohho
              Jul 15 '13 at 4:46






            • 3





              I get that same Bad configuration option error on OSX 10.8.4.

              – Nick Heiner
              Jul 18 '13 at 19:57








            • 10





              Generally, you put these two commands into different parts of the system. Only ServerAliveInterval on the OSX client side... and only ClientAliveInterval on the sshd config file...

              – ftrotter
              Oct 23 '13 at 22:56














            229












            229








            229







            I have tried this in /etc/ssh/ssh_config for Linux and Mac:



            Host *
            ServerAliveInterval 120


            This is how often, in seconds, it should send a keepalive message to the server. If that doesn't work then train a monkey to press enter every two minutes while you work.



            You could set either ServerAliveInterval in /etc/ssh/ssh_config of the client machine or ClientAliveInterval in /etc/ssh/sshd_config of the server machine. Try reducing the interval if you are still getting the error.



            Configuration for a single user can be set in file ~/.ssh/config both on the server and client side. Make sure the file has correct permissions chmod 644 ~/.ssh/config.






            share|improve this answer















            I have tried this in /etc/ssh/ssh_config for Linux and Mac:



            Host *
            ServerAliveInterval 120


            This is how often, in seconds, it should send a keepalive message to the server. If that doesn't work then train a monkey to press enter every two minutes while you work.



            You could set either ServerAliveInterval in /etc/ssh/ssh_config of the client machine or ClientAliveInterval in /etc/ssh/sshd_config of the server machine. Try reducing the interval if you are still getting the error.



            Configuration for a single user can be set in file ~/.ssh/config both on the server and client side. Make sure the file has correct permissions chmod 644 ~/.ssh/config.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Dec 20 '17 at 23:58









            teekarna

            1033




            1033










            answered May 26 '12 at 11:49









            Aram KocharyanAram Kocharyan

            2,4852108




            2,4852108








            • 1





              Yeah I do similar and it works quite well for most things.

              – Oli
              Aug 25 '12 at 0:25






            • 3





              I'm not on a Mac, but Ubuntu 12.04 and the file for this operating system also seems to be ~/.ssh/config.

              – H2ONaCl
              Dec 14 '12 at 13:26






            • 5





              OS X 10.8.4 gives an error Bad configuration option: ClientAliveInterval

              – ohho
              Jul 15 '13 at 4:46






            • 3





              I get that same Bad configuration option error on OSX 10.8.4.

              – Nick Heiner
              Jul 18 '13 at 19:57








            • 10





              Generally, you put these two commands into different parts of the system. Only ServerAliveInterval on the OSX client side... and only ClientAliveInterval on the sshd config file...

              – ftrotter
              Oct 23 '13 at 22:56














            • 1





              Yeah I do similar and it works quite well for most things.

              – Oli
              Aug 25 '12 at 0:25






            • 3





              I'm not on a Mac, but Ubuntu 12.04 and the file for this operating system also seems to be ~/.ssh/config.

              – H2ONaCl
              Dec 14 '12 at 13:26






            • 5





              OS X 10.8.4 gives an error Bad configuration option: ClientAliveInterval

              – ohho
              Jul 15 '13 at 4:46






            • 3





              I get that same Bad configuration option error on OSX 10.8.4.

              – Nick Heiner
              Jul 18 '13 at 19:57








            • 10





              Generally, you put these two commands into different parts of the system. Only ServerAliveInterval on the OSX client side... and only ClientAliveInterval on the sshd config file...

              – ftrotter
              Oct 23 '13 at 22:56








            1




            1





            Yeah I do similar and it works quite well for most things.

            – Oli
            Aug 25 '12 at 0:25





            Yeah I do similar and it works quite well for most things.

            – Oli
            Aug 25 '12 at 0:25




            3




            3





            I'm not on a Mac, but Ubuntu 12.04 and the file for this operating system also seems to be ~/.ssh/config.

            – H2ONaCl
            Dec 14 '12 at 13:26





            I'm not on a Mac, but Ubuntu 12.04 and the file for this operating system also seems to be ~/.ssh/config.

            – H2ONaCl
            Dec 14 '12 at 13:26




            5




            5





            OS X 10.8.4 gives an error Bad configuration option: ClientAliveInterval

            – ohho
            Jul 15 '13 at 4:46





            OS X 10.8.4 gives an error Bad configuration option: ClientAliveInterval

            – ohho
            Jul 15 '13 at 4:46




            3




            3





            I get that same Bad configuration option error on OSX 10.8.4.

            – Nick Heiner
            Jul 18 '13 at 19:57







            I get that same Bad configuration option error on OSX 10.8.4.

            – Nick Heiner
            Jul 18 '13 at 19:57






            10




            10





            Generally, you put these two commands into different parts of the system. Only ServerAliveInterval on the OSX client side... and only ClientAliveInterval on the sshd config file...

            – ftrotter
            Oct 23 '13 at 22:56





            Generally, you put these two commands into different parts of the system. Only ServerAliveInterval on the OSX client side... and only ClientAliveInterval on the sshd config file...

            – ftrotter
            Oct 23 '13 at 22:56













            78














            SSH sessions may break due to numerous and possibly unavoidable reasons.



            A useful utility which can be used to mitigate problems caused by this is called screen. Screen is a powerful utility that allows you to control multiple terminals which will stay alive independently of the ssh session. For example, if you run screen in an ssh session you will see a new terminal open and you can use that to run jobs. Lets say your ssh session dies in the process. Running screen -d then screen -r will reopen the last session and you will be able to continue from there. Make sure you read some of the documentation before using it.






            share|improve this answer



















            • 4





              This is probably the best answer, I'm not sure why it's not voted up higher. The other "fixes" are helpful in the special case where you would actually care about maintaining an SSH connection, but in most use cases I imagine the real concern is that the intended processes continue to run, regardless of any client/server connection issues whatsoever.

              – Paul McMurdie
              Jun 3 '13 at 17:33






            • 15





              I would also add Tmux as an alternative to screen. I find it more versatile and stable than screen.

              – fridaymeetssunday
              Jan 5 '15 at 15:28






            • 2





              just leaving this here for future reference – you can conveniently run screen -d -r to recover your last session.

              – doplumi
              Nov 21 '16 at 7:41













            • Or simply screen -dr. Or screen -x depending on what you're planning on doing. The point is, one ought to know what all those switches do, so that one can use the appropriate ones and not just blindly follow internet people's suggestions. There's a nice compact summary available here: ss64.com/bash/screen.html

              – flith
              May 28 '18 at 6:27
















            78














            SSH sessions may break due to numerous and possibly unavoidable reasons.



            A useful utility which can be used to mitigate problems caused by this is called screen. Screen is a powerful utility that allows you to control multiple terminals which will stay alive independently of the ssh session. For example, if you run screen in an ssh session you will see a new terminal open and you can use that to run jobs. Lets say your ssh session dies in the process. Running screen -d then screen -r will reopen the last session and you will be able to continue from there. Make sure you read some of the documentation before using it.






            share|improve this answer



















            • 4





              This is probably the best answer, I'm not sure why it's not voted up higher. The other "fixes" are helpful in the special case where you would actually care about maintaining an SSH connection, but in most use cases I imagine the real concern is that the intended processes continue to run, regardless of any client/server connection issues whatsoever.

              – Paul McMurdie
              Jun 3 '13 at 17:33






            • 15





              I would also add Tmux as an alternative to screen. I find it more versatile and stable than screen.

              – fridaymeetssunday
              Jan 5 '15 at 15:28






            • 2





              just leaving this here for future reference – you can conveniently run screen -d -r to recover your last session.

              – doplumi
              Nov 21 '16 at 7:41













            • Or simply screen -dr. Or screen -x depending on what you're planning on doing. The point is, one ought to know what all those switches do, so that one can use the appropriate ones and not just blindly follow internet people's suggestions. There's a nice compact summary available here: ss64.com/bash/screen.html

              – flith
              May 28 '18 at 6:27














            78












            78








            78







            SSH sessions may break due to numerous and possibly unavoidable reasons.



            A useful utility which can be used to mitigate problems caused by this is called screen. Screen is a powerful utility that allows you to control multiple terminals which will stay alive independently of the ssh session. For example, if you run screen in an ssh session you will see a new terminal open and you can use that to run jobs. Lets say your ssh session dies in the process. Running screen -d then screen -r will reopen the last session and you will be able to continue from there. Make sure you read some of the documentation before using it.






            share|improve this answer













            SSH sessions may break due to numerous and possibly unavoidable reasons.



            A useful utility which can be used to mitigate problems caused by this is called screen. Screen is a powerful utility that allows you to control multiple terminals which will stay alive independently of the ssh session. For example, if you run screen in an ssh session you will see a new terminal open and you can use that to run jobs. Lets say your ssh session dies in the process. Running screen -d then screen -r will reopen the last session and you will be able to continue from there. Make sure you read some of the documentation before using it.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Oct 4 '12 at 16:28









            eltommoeltommo

            1,506911




            1,506911








            • 4





              This is probably the best answer, I'm not sure why it's not voted up higher. The other "fixes" are helpful in the special case where you would actually care about maintaining an SSH connection, but in most use cases I imagine the real concern is that the intended processes continue to run, regardless of any client/server connection issues whatsoever.

              – Paul McMurdie
              Jun 3 '13 at 17:33






            • 15





              I would also add Tmux as an alternative to screen. I find it more versatile and stable than screen.

              – fridaymeetssunday
              Jan 5 '15 at 15:28






            • 2





              just leaving this here for future reference – you can conveniently run screen -d -r to recover your last session.

              – doplumi
              Nov 21 '16 at 7:41













            • Or simply screen -dr. Or screen -x depending on what you're planning on doing. The point is, one ought to know what all those switches do, so that one can use the appropriate ones and not just blindly follow internet people's suggestions. There's a nice compact summary available here: ss64.com/bash/screen.html

              – flith
              May 28 '18 at 6:27














            • 4





              This is probably the best answer, I'm not sure why it's not voted up higher. The other "fixes" are helpful in the special case where you would actually care about maintaining an SSH connection, but in most use cases I imagine the real concern is that the intended processes continue to run, regardless of any client/server connection issues whatsoever.

              – Paul McMurdie
              Jun 3 '13 at 17:33






            • 15





              I would also add Tmux as an alternative to screen. I find it more versatile and stable than screen.

              – fridaymeetssunday
              Jan 5 '15 at 15:28






            • 2





              just leaving this here for future reference – you can conveniently run screen -d -r to recover your last session.

              – doplumi
              Nov 21 '16 at 7:41













            • Or simply screen -dr. Or screen -x depending on what you're planning on doing. The point is, one ought to know what all those switches do, so that one can use the appropriate ones and not just blindly follow internet people's suggestions. There's a nice compact summary available here: ss64.com/bash/screen.html

              – flith
              May 28 '18 at 6:27








            4




            4





            This is probably the best answer, I'm not sure why it's not voted up higher. The other "fixes" are helpful in the special case where you would actually care about maintaining an SSH connection, but in most use cases I imagine the real concern is that the intended processes continue to run, regardless of any client/server connection issues whatsoever.

            – Paul McMurdie
            Jun 3 '13 at 17:33





            This is probably the best answer, I'm not sure why it's not voted up higher. The other "fixes" are helpful in the special case where you would actually care about maintaining an SSH connection, but in most use cases I imagine the real concern is that the intended processes continue to run, regardless of any client/server connection issues whatsoever.

            – Paul McMurdie
            Jun 3 '13 at 17:33




            15




            15





            I would also add Tmux as an alternative to screen. I find it more versatile and stable than screen.

            – fridaymeetssunday
            Jan 5 '15 at 15:28





            I would also add Tmux as an alternative to screen. I find it more versatile and stable than screen.

            – fridaymeetssunday
            Jan 5 '15 at 15:28




            2




            2





            just leaving this here for future reference – you can conveniently run screen -d -r to recover your last session.

            – doplumi
            Nov 21 '16 at 7:41







            just leaving this here for future reference – you can conveniently run screen -d -r to recover your last session.

            – doplumi
            Nov 21 '16 at 7:41















            Or simply screen -dr. Or screen -x depending on what you're planning on doing. The point is, one ought to know what all those switches do, so that one can use the appropriate ones and not just blindly follow internet people's suggestions. There's a nice compact summary available here: ss64.com/bash/screen.html

            – flith
            May 28 '18 at 6:27





            Or simply screen -dr. Or screen -x depending on what you're planning on doing. The point is, one ought to know what all those switches do, so that one can use the appropriate ones and not just blindly follow internet people's suggestions. There's a nice compact summary available here: ss64.com/bash/screen.html

            – flith
            May 28 '18 at 6:27











            42














            Client configuration



            Try creating the file:



            ~/.ssh/config


            Add the contents:



            Host *
            ServerAliveInterval 30
            ServerAliveCountMax 5


            Now ssh to your server and see if your problem is fixed. ClientAliveInterval option is only useful when configuring the ssh server (aka sshd), it does not change a thing on the ssh client side, so don't use it in the above configuration file.



            This will send a hello-are-you-there signal to the server if no packets have been received in the preceding 30 seconds (as specified above). However, if the number of consecutive hello-are-you-there signals reach ServerAliveCountMax then ssh will disconnect from the server. This value is defaulting to 3 (so 3*30 = 90 seconds without server activity), increase it if it suits your needs. There are alot more config options to the .ssh/config file and you could read:



            Using an SSH Config File



            For more information on other options. You may not want to apply this to every server you connect to which this example will. Or restrain it to only a particular server by replacing the line Host * with Host <IP> (replace by an IP address, see ssh_config man page).



            Server configuration



            Similarly you can tell the server to be gentle with your clients. The configuration file is /etc/ssh/sshd_config.



            ClientAliveInterval 20
            ClientAliveCountMax 5


            You can either deactivate it by setting ClientAliveInterval to 0 or tweak ClientAliveInterval and ClientAliveCountMax to set a maximum ssh client inactivity without responding to the probes. One advantage of this settings over TCPKeepAlive is that the signals are sent through the encrypted channels, so it is less likely to be spoofable.






            share|improve this answer


























            • It doesn't work. I am facing the same error again.

              – user997704
              Oct 6 '13 at 4:59






            • 2





              Try it straight from the command line and go lower: ssh -o ServerAliveInterval=5 user@host

              – Matt
              Oct 6 '13 at 10:46













            • Tried that too..doesn't work. I really don't know what is going on with my system

              – user997704
              Nov 15 '13 at 8:39






            • 1





              It's ClientAliveCountMax, NOT ClientAliveMaxCount

              – David G
              Sep 5 '15 at 1:11











            • @DavidG Please edit the answer with your corrections.

              – CivMeierFan
              Feb 3 '16 at 17:35
















            42














            Client configuration



            Try creating the file:



            ~/.ssh/config


            Add the contents:



            Host *
            ServerAliveInterval 30
            ServerAliveCountMax 5


            Now ssh to your server and see if your problem is fixed. ClientAliveInterval option is only useful when configuring the ssh server (aka sshd), it does not change a thing on the ssh client side, so don't use it in the above configuration file.



            This will send a hello-are-you-there signal to the server if no packets have been received in the preceding 30 seconds (as specified above). However, if the number of consecutive hello-are-you-there signals reach ServerAliveCountMax then ssh will disconnect from the server. This value is defaulting to 3 (so 3*30 = 90 seconds without server activity), increase it if it suits your needs. There are alot more config options to the .ssh/config file and you could read:



            Using an SSH Config File



            For more information on other options. You may not want to apply this to every server you connect to which this example will. Or restrain it to only a particular server by replacing the line Host * with Host <IP> (replace by an IP address, see ssh_config man page).



            Server configuration



            Similarly you can tell the server to be gentle with your clients. The configuration file is /etc/ssh/sshd_config.



            ClientAliveInterval 20
            ClientAliveCountMax 5


            You can either deactivate it by setting ClientAliveInterval to 0 or tweak ClientAliveInterval and ClientAliveCountMax to set a maximum ssh client inactivity without responding to the probes. One advantage of this settings over TCPKeepAlive is that the signals are sent through the encrypted channels, so it is less likely to be spoofable.






            share|improve this answer


























            • It doesn't work. I am facing the same error again.

              – user997704
              Oct 6 '13 at 4:59






            • 2





              Try it straight from the command line and go lower: ssh -o ServerAliveInterval=5 user@host

              – Matt
              Oct 6 '13 at 10:46













            • Tried that too..doesn't work. I really don't know what is going on with my system

              – user997704
              Nov 15 '13 at 8:39






            • 1





              It's ClientAliveCountMax, NOT ClientAliveMaxCount

              – David G
              Sep 5 '15 at 1:11











            • @DavidG Please edit the answer with your corrections.

              – CivMeierFan
              Feb 3 '16 at 17:35














            42












            42








            42







            Client configuration



            Try creating the file:



            ~/.ssh/config


            Add the contents:



            Host *
            ServerAliveInterval 30
            ServerAliveCountMax 5


            Now ssh to your server and see if your problem is fixed. ClientAliveInterval option is only useful when configuring the ssh server (aka sshd), it does not change a thing on the ssh client side, so don't use it in the above configuration file.



            This will send a hello-are-you-there signal to the server if no packets have been received in the preceding 30 seconds (as specified above). However, if the number of consecutive hello-are-you-there signals reach ServerAliveCountMax then ssh will disconnect from the server. This value is defaulting to 3 (so 3*30 = 90 seconds without server activity), increase it if it suits your needs. There are alot more config options to the .ssh/config file and you could read:



            Using an SSH Config File



            For more information on other options. You may not want to apply this to every server you connect to which this example will. Or restrain it to only a particular server by replacing the line Host * with Host <IP> (replace by an IP address, see ssh_config man page).



            Server configuration



            Similarly you can tell the server to be gentle with your clients. The configuration file is /etc/ssh/sshd_config.



            ClientAliveInterval 20
            ClientAliveCountMax 5


            You can either deactivate it by setting ClientAliveInterval to 0 or tweak ClientAliveInterval and ClientAliveCountMax to set a maximum ssh client inactivity without responding to the probes. One advantage of this settings over TCPKeepAlive is that the signals are sent through the encrypted channels, so it is less likely to be spoofable.






            share|improve this answer















            Client configuration



            Try creating the file:



            ~/.ssh/config


            Add the contents:



            Host *
            ServerAliveInterval 30
            ServerAliveCountMax 5


            Now ssh to your server and see if your problem is fixed. ClientAliveInterval option is only useful when configuring the ssh server (aka sshd), it does not change a thing on the ssh client side, so don't use it in the above configuration file.



            This will send a hello-are-you-there signal to the server if no packets have been received in the preceding 30 seconds (as specified above). However, if the number of consecutive hello-are-you-there signals reach ServerAliveCountMax then ssh will disconnect from the server. This value is defaulting to 3 (so 3*30 = 90 seconds without server activity), increase it if it suits your needs. There are alot more config options to the .ssh/config file and you could read:



            Using an SSH Config File



            For more information on other options. You may not want to apply this to every server you connect to which this example will. Or restrain it to only a particular server by replacing the line Host * with Host <IP> (replace by an IP address, see ssh_config man page).



            Server configuration



            Similarly you can tell the server to be gentle with your clients. The configuration file is /etc/ssh/sshd_config.



            ClientAliveInterval 20
            ClientAliveCountMax 5


            You can either deactivate it by setting ClientAliveInterval to 0 or tweak ClientAliveInterval and ClientAliveCountMax to set a maximum ssh client inactivity without responding to the probes. One advantage of this settings over TCPKeepAlive is that the signals are sent through the encrypted channels, so it is less likely to be spoofable.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Feb 5 '16 at 14:30









            David Foerster

            28k1365111




            28k1365111










            answered Oct 6 '13 at 2:54









            MattMatt

            48244




            48244













            • It doesn't work. I am facing the same error again.

              – user997704
              Oct 6 '13 at 4:59






            • 2





              Try it straight from the command line and go lower: ssh -o ServerAliveInterval=5 user@host

              – Matt
              Oct 6 '13 at 10:46













            • Tried that too..doesn't work. I really don't know what is going on with my system

              – user997704
              Nov 15 '13 at 8:39






            • 1





              It's ClientAliveCountMax, NOT ClientAliveMaxCount

              – David G
              Sep 5 '15 at 1:11











            • @DavidG Please edit the answer with your corrections.

              – CivMeierFan
              Feb 3 '16 at 17:35



















            • It doesn't work. I am facing the same error again.

              – user997704
              Oct 6 '13 at 4:59






            • 2





              Try it straight from the command line and go lower: ssh -o ServerAliveInterval=5 user@host

              – Matt
              Oct 6 '13 at 10:46













            • Tried that too..doesn't work. I really don't know what is going on with my system

              – user997704
              Nov 15 '13 at 8:39






            • 1





              It's ClientAliveCountMax, NOT ClientAliveMaxCount

              – David G
              Sep 5 '15 at 1:11











            • @DavidG Please edit the answer with your corrections.

              – CivMeierFan
              Feb 3 '16 at 17:35

















            It doesn't work. I am facing the same error again.

            – user997704
            Oct 6 '13 at 4:59





            It doesn't work. I am facing the same error again.

            – user997704
            Oct 6 '13 at 4:59




            2




            2





            Try it straight from the command line and go lower: ssh -o ServerAliveInterval=5 user@host

            – Matt
            Oct 6 '13 at 10:46







            Try it straight from the command line and go lower: ssh -o ServerAliveInterval=5 user@host

            – Matt
            Oct 6 '13 at 10:46















            Tried that too..doesn't work. I really don't know what is going on with my system

            – user997704
            Nov 15 '13 at 8:39





            Tried that too..doesn't work. I really don't know what is going on with my system

            – user997704
            Nov 15 '13 at 8:39




            1




            1





            It's ClientAliveCountMax, NOT ClientAliveMaxCount

            – David G
            Sep 5 '15 at 1:11





            It's ClientAliveCountMax, NOT ClientAliveMaxCount

            – David G
            Sep 5 '15 at 1:11













            @DavidG Please edit the answer with your corrections.

            – CivMeierFan
            Feb 3 '16 at 17:35





            @DavidG Please edit the answer with your corrections.

            – CivMeierFan
            Feb 3 '16 at 17:35











            22














            I'm remotely upgrading an Ubuntu server from lucid to precise and lost the ssh connection in the middle of the upgrade with the message "Write failed. Brocken pipe". ClientAliveInterval and ServerAliveInterval did nothing. The solution is to turn on TCPKeepAlive options in client ssh:



            TCPKeepAlive yes


            in



            /etc/ssh/ssh_config





            share|improve this answer






























              22














              I'm remotely upgrading an Ubuntu server from lucid to precise and lost the ssh connection in the middle of the upgrade with the message "Write failed. Brocken pipe". ClientAliveInterval and ServerAliveInterval did nothing. The solution is to turn on TCPKeepAlive options in client ssh:



              TCPKeepAlive yes


              in



              /etc/ssh/ssh_config





              share|improve this answer




























                22












                22








                22







                I'm remotely upgrading an Ubuntu server from lucid to precise and lost the ssh connection in the middle of the upgrade with the message "Write failed. Brocken pipe". ClientAliveInterval and ServerAliveInterval did nothing. The solution is to turn on TCPKeepAlive options in client ssh:



                TCPKeepAlive yes


                in



                /etc/ssh/ssh_config





                share|improve this answer















                I'm remotely upgrading an Ubuntu server from lucid to precise and lost the ssh connection in the middle of the upgrade with the message "Write failed. Brocken pipe". ClientAliveInterval and ServerAliveInterval did nothing. The solution is to turn on TCPKeepAlive options in client ssh:



                TCPKeepAlive yes


                in



                /etc/ssh/ssh_config






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Mar 30 '13 at 22:30









                Brad Koch

                1279




                1279










                answered Oct 7 '12 at 18:40









                Alexey SviridovAlexey Sviridov

                32526




                32526























                    19














                    For the client, edit your ~/.ssh/config (or /etc/ssh/ssh_config) file as follow:



                    Host *
                    TCPKeepAlive yes
                    ServerAliveInterval 120



                    TCPKeepAlive - Specifies whether the system should send TCP keepalive
                    messages to the other side. If they are sent, death of the connection
                    or crash of one of the machines will be properly noticed. However,
                    this means that connections will die if the route is down temporarily,
                    and some people find it annoying (The default is 'yes').



                    ServerAliveInterval - Sets a timeout interval in seconds after which
                    if no data has been received from the server, ssh(1) will send a
                    message through the encrypted channel to request a response from the
                    server. The default is 0, indicating that these messages will not be
                    sent to the server.






                    For the server, edit your /etc/ssh/sshd_config as:



                    ClientAliveInterval 600
                    ClientAliveCountMax 0


                    If you want ssh client to exit (timeout) automatically after 10 minutes (600 seconds).




                    ClientAliveCountMax – This indicates the total number of checkalive
                    message sent by the ssh server without getting any response from the
                    ssh client. Default is 3.



                    ClientAliveInterval – This indicates the timeout in seconds. After x
                    number of seconds, ssh server will send a message to the client asking
                    for response. Deafult is 0 (server will not send message to client to
                    check.).






                    See also: What do the options ServerAliveInterval and ClientAliveInterval in sshd_config do, precisely?






                    share|improve this answer


























                    • Setting a ServerAliveCountMax higher than the default on the client should also help keep the connection live for slow connections.

                      – rippledj
                      Oct 1 '18 at 20:29
















                    19














                    For the client, edit your ~/.ssh/config (or /etc/ssh/ssh_config) file as follow:



                    Host *
                    TCPKeepAlive yes
                    ServerAliveInterval 120



                    TCPKeepAlive - Specifies whether the system should send TCP keepalive
                    messages to the other side. If they are sent, death of the connection
                    or crash of one of the machines will be properly noticed. However,
                    this means that connections will die if the route is down temporarily,
                    and some people find it annoying (The default is 'yes').



                    ServerAliveInterval - Sets a timeout interval in seconds after which
                    if no data has been received from the server, ssh(1) will send a
                    message through the encrypted channel to request a response from the
                    server. The default is 0, indicating that these messages will not be
                    sent to the server.






                    For the server, edit your /etc/ssh/sshd_config as:



                    ClientAliveInterval 600
                    ClientAliveCountMax 0


                    If you want ssh client to exit (timeout) automatically after 10 minutes (600 seconds).




                    ClientAliveCountMax – This indicates the total number of checkalive
                    message sent by the ssh server without getting any response from the
                    ssh client. Default is 3.



                    ClientAliveInterval – This indicates the timeout in seconds. After x
                    number of seconds, ssh server will send a message to the client asking
                    for response. Deafult is 0 (server will not send message to client to
                    check.).






                    See also: What do the options ServerAliveInterval and ClientAliveInterval in sshd_config do, precisely?






                    share|improve this answer


























                    • Setting a ServerAliveCountMax higher than the default on the client should also help keep the connection live for slow connections.

                      – rippledj
                      Oct 1 '18 at 20:29














                    19












                    19








                    19







                    For the client, edit your ~/.ssh/config (or /etc/ssh/ssh_config) file as follow:



                    Host *
                    TCPKeepAlive yes
                    ServerAliveInterval 120



                    TCPKeepAlive - Specifies whether the system should send TCP keepalive
                    messages to the other side. If they are sent, death of the connection
                    or crash of one of the machines will be properly noticed. However,
                    this means that connections will die if the route is down temporarily,
                    and some people find it annoying (The default is 'yes').



                    ServerAliveInterval - Sets a timeout interval in seconds after which
                    if no data has been received from the server, ssh(1) will send a
                    message through the encrypted channel to request a response from the
                    server. The default is 0, indicating that these messages will not be
                    sent to the server.






                    For the server, edit your /etc/ssh/sshd_config as:



                    ClientAliveInterval 600
                    ClientAliveCountMax 0


                    If you want ssh client to exit (timeout) automatically after 10 minutes (600 seconds).




                    ClientAliveCountMax – This indicates the total number of checkalive
                    message sent by the ssh server without getting any response from the
                    ssh client. Default is 3.



                    ClientAliveInterval – This indicates the timeout in seconds. After x
                    number of seconds, ssh server will send a message to the client asking
                    for response. Deafult is 0 (server will not send message to client to
                    check.).






                    See also: What do the options ServerAliveInterval and ClientAliveInterval in sshd_config do, precisely?






                    share|improve this answer















                    For the client, edit your ~/.ssh/config (or /etc/ssh/ssh_config) file as follow:



                    Host *
                    TCPKeepAlive yes
                    ServerAliveInterval 120



                    TCPKeepAlive - Specifies whether the system should send TCP keepalive
                    messages to the other side. If they are sent, death of the connection
                    or crash of one of the machines will be properly noticed. However,
                    this means that connections will die if the route is down temporarily,
                    and some people find it annoying (The default is 'yes').



                    ServerAliveInterval - Sets a timeout interval in seconds after which
                    if no data has been received from the server, ssh(1) will send a
                    message through the encrypted channel to request a response from the
                    server. The default is 0, indicating that these messages will not be
                    sent to the server.






                    For the server, edit your /etc/ssh/sshd_config as:



                    ClientAliveInterval 600
                    ClientAliveCountMax 0


                    If you want ssh client to exit (timeout) automatically after 10 minutes (600 seconds).




                    ClientAliveCountMax – This indicates the total number of checkalive
                    message sent by the ssh server without getting any response from the
                    ssh client. Default is 3.



                    ClientAliveInterval – This indicates the timeout in seconds. After x
                    number of seconds, ssh server will send a message to the client asking
                    for response. Deafult is 0 (server will not send message to client to
                    check.).






                    See also: What do the options ServerAliveInterval and ClientAliveInterval in sshd_config do, precisely?







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Apr 13 '17 at 12:37









                    Community

                    1




                    1










                    answered Oct 2 '14 at 13:52









                    kenorbkenorb

                    4,36613953




                    4,36613953













                    • Setting a ServerAliveCountMax higher than the default on the client should also help keep the connection live for slow connections.

                      – rippledj
                      Oct 1 '18 at 20:29



















                    • Setting a ServerAliveCountMax higher than the default on the client should also help keep the connection live for slow connections.

                      – rippledj
                      Oct 1 '18 at 20:29

















                    Setting a ServerAliveCountMax higher than the default on the client should also help keep the connection live for slow connections.

                    – rippledj
                    Oct 1 '18 at 20:29





                    Setting a ServerAliveCountMax higher than the default on the client should also help keep the connection live for slow connections.

                    – rippledj
                    Oct 1 '18 at 20:29











                    16














                    I absolutely love Mosh. I frequently ssh into a server, close my laptop and go to a cafe, open it up and carry on as if nothing changed.




                    Mosh (mobile shell)



                    Remote terminal application that allows roaming, supports intermittent
                    connectivity
                    , and provides intelligent local
                    echo
                    and line editing of user keystrokes.



                    Mosh is a replacement for SSH. It's more robust and responsive,
                    especially over Wi-Fi, cellular, and long-distance links.



                    Mosh is free software, available for GNU/Linux, FreeBSD, Solaris, Mac OS X, and Android.







                    share|improve this answer




























                      16














                      I absolutely love Mosh. I frequently ssh into a server, close my laptop and go to a cafe, open it up and carry on as if nothing changed.




                      Mosh (mobile shell)



                      Remote terminal application that allows roaming, supports intermittent
                      connectivity
                      , and provides intelligent local
                      echo
                      and line editing of user keystrokes.



                      Mosh is a replacement for SSH. It's more robust and responsive,
                      especially over Wi-Fi, cellular, and long-distance links.



                      Mosh is free software, available for GNU/Linux, FreeBSD, Solaris, Mac OS X, and Android.







                      share|improve this answer


























                        16












                        16








                        16







                        I absolutely love Mosh. I frequently ssh into a server, close my laptop and go to a cafe, open it up and carry on as if nothing changed.




                        Mosh (mobile shell)



                        Remote terminal application that allows roaming, supports intermittent
                        connectivity
                        , and provides intelligent local
                        echo
                        and line editing of user keystrokes.



                        Mosh is a replacement for SSH. It's more robust and responsive,
                        especially over Wi-Fi, cellular, and long-distance links.



                        Mosh is free software, available for GNU/Linux, FreeBSD, Solaris, Mac OS X, and Android.







                        share|improve this answer













                        I absolutely love Mosh. I frequently ssh into a server, close my laptop and go to a cafe, open it up and carry on as if nothing changed.




                        Mosh (mobile shell)



                        Remote terminal application that allows roaming, supports intermittent
                        connectivity
                        , and provides intelligent local
                        echo
                        and line editing of user keystrokes.



                        Mosh is a replacement for SSH. It's more robust and responsive,
                        especially over Wi-Fi, cellular, and long-distance links.



                        Mosh is free software, available for GNU/Linux, FreeBSD, Solaris, Mac OS X, and Android.








                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Sep 30 '14 at 18:48









                        JakeJake

                        26123




                        26123























                            5














                            For me, I was getting Write failed: Broken pipe even when I was actively typing in vim or at the shell prompt. I couldn't browse the internet locally either for awhile either. (I was connecting remotely to Ubuntu using Terminal.)



                            Others in my network stream a lot of video from Netflix and other places. I can't prove it, but I suspect its an ISP or router issue. For example, Verizon and Netflix are pointing fingers at each other for their customer's network problems.



                            If you've got a dial-up connection and are streaming video or music with a simultaneous SSH or telnet connection, it's inevitable at some point you'll get a broken pipe message. Upgrading my ISPs broadband package seemed to make my broken connection less frequent.






                            share|improve this answer




























                              5














                              For me, I was getting Write failed: Broken pipe even when I was actively typing in vim or at the shell prompt. I couldn't browse the internet locally either for awhile either. (I was connecting remotely to Ubuntu using Terminal.)



                              Others in my network stream a lot of video from Netflix and other places. I can't prove it, but I suspect its an ISP or router issue. For example, Verizon and Netflix are pointing fingers at each other for their customer's network problems.



                              If you've got a dial-up connection and are streaming video or music with a simultaneous SSH or telnet connection, it's inevitable at some point you'll get a broken pipe message. Upgrading my ISPs broadband package seemed to make my broken connection less frequent.






                              share|improve this answer


























                                5












                                5








                                5







                                For me, I was getting Write failed: Broken pipe even when I was actively typing in vim or at the shell prompt. I couldn't browse the internet locally either for awhile either. (I was connecting remotely to Ubuntu using Terminal.)



                                Others in my network stream a lot of video from Netflix and other places. I can't prove it, but I suspect its an ISP or router issue. For example, Verizon and Netflix are pointing fingers at each other for their customer's network problems.



                                If you've got a dial-up connection and are streaming video or music with a simultaneous SSH or telnet connection, it's inevitable at some point you'll get a broken pipe message. Upgrading my ISPs broadband package seemed to make my broken connection less frequent.






                                share|improve this answer













                                For me, I was getting Write failed: Broken pipe even when I was actively typing in vim or at the shell prompt. I couldn't browse the internet locally either for awhile either. (I was connecting remotely to Ubuntu using Terminal.)



                                Others in my network stream a lot of video from Netflix and other places. I can't prove it, but I suspect its an ISP or router issue. For example, Verizon and Netflix are pointing fingers at each other for their customer's network problems.



                                If you've got a dial-up connection and are streaming video or music with a simultaneous SSH or telnet connection, it's inevitable at some point you'll get a broken pipe message. Upgrading my ISPs broadband package seemed to make my broken connection less frequent.







                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered Jul 30 '14 at 13:33









                                ParagParag

                                4021511




                                4021511























                                    3














                                    I have a script on the remote server that never seems to fails, regardless of the SSH configuration client or server.



                                    #!/bin/bash
                                    while true; do date; sleep 10; done;


                                    Save it to some dummy.sh file and quickly run it before you minimize the window or move away from it. It will keep printing the current time stamp on the server and keeps your connection alive as long as the connection is not dropped by any other reason. When you get back to that terminal, just hit CTRL+C and keep working.






                                    share|improve this answer



















                                    • 8





                                      or simply leave top running

                                      – Eben Geer
                                      Dec 19 '13 at 22:43
















                                    3














                                    I have a script on the remote server that never seems to fails, regardless of the SSH configuration client or server.



                                    #!/bin/bash
                                    while true; do date; sleep 10; done;


                                    Save it to some dummy.sh file and quickly run it before you minimize the window or move away from it. It will keep printing the current time stamp on the server and keeps your connection alive as long as the connection is not dropped by any other reason. When you get back to that terminal, just hit CTRL+C and keep working.






                                    share|improve this answer



















                                    • 8





                                      or simply leave top running

                                      – Eben Geer
                                      Dec 19 '13 at 22:43














                                    3












                                    3








                                    3







                                    I have a script on the remote server that never seems to fails, regardless of the SSH configuration client or server.



                                    #!/bin/bash
                                    while true; do date; sleep 10; done;


                                    Save it to some dummy.sh file and quickly run it before you minimize the window or move away from it. It will keep printing the current time stamp on the server and keeps your connection alive as long as the connection is not dropped by any other reason. When you get back to that terminal, just hit CTRL+C and keep working.






                                    share|improve this answer













                                    I have a script on the remote server that never seems to fails, regardless of the SSH configuration client or server.



                                    #!/bin/bash
                                    while true; do date; sleep 10; done;


                                    Save it to some dummy.sh file and quickly run it before you minimize the window or move away from it. It will keep printing the current time stamp on the server and keeps your connection alive as long as the connection is not dropped by any other reason. When you get back to that terminal, just hit CTRL+C and keep working.







                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Sep 9 '13 at 16:50









                                    JulioHMJulioHM

                                    476149




                                    476149








                                    • 8





                                      or simply leave top running

                                      – Eben Geer
                                      Dec 19 '13 at 22:43














                                    • 8





                                      or simply leave top running

                                      – Eben Geer
                                      Dec 19 '13 at 22:43








                                    8




                                    8





                                    or simply leave top running

                                    – Eben Geer
                                    Dec 19 '13 at 22:43





                                    or simply leave top running

                                    – Eben Geer
                                    Dec 19 '13 at 22:43











                                    1














                                    You can add these args every time you invoke ssh: -o ServerAliveInterval=15 -o ServerAliveCountMax=3



                                    You don't have to edit /etc/ssh/*config files if you do this.



                                    You can create an bash alias or function or script to make this easy.



                                    E.g. these bash functions, you can add into your .bashrc, do_ssh is used manually to turn on keepalives. do_ssh_pty is used within scripts to set pty and avoid prompts.



                                    do_ssh() {
                                    ssh -o ServerAliveInterval=15 -o ServerAliveCountMax=3 $*
                                    }

                                    do_ssh_pty() {
                                    ssh -tt -o "BatchMode=yes" -o "StrictHostKeyChecking=no" -o ServerAliveInterval=15 -o ServerAliveCountMax=3 $*
                                    }


                                    Now do_ssh user@host can be used or do_ssh user@host <args> <command> and keepalives will be active.






                                    share|improve this answer




























                                      1














                                      You can add these args every time you invoke ssh: -o ServerAliveInterval=15 -o ServerAliveCountMax=3



                                      You don't have to edit /etc/ssh/*config files if you do this.



                                      You can create an bash alias or function or script to make this easy.



                                      E.g. these bash functions, you can add into your .bashrc, do_ssh is used manually to turn on keepalives. do_ssh_pty is used within scripts to set pty and avoid prompts.



                                      do_ssh() {
                                      ssh -o ServerAliveInterval=15 -o ServerAliveCountMax=3 $*
                                      }

                                      do_ssh_pty() {
                                      ssh -tt -o "BatchMode=yes" -o "StrictHostKeyChecking=no" -o ServerAliveInterval=15 -o ServerAliveCountMax=3 $*
                                      }


                                      Now do_ssh user@host can be used or do_ssh user@host <args> <command> and keepalives will be active.






                                      share|improve this answer


























                                        1












                                        1








                                        1







                                        You can add these args every time you invoke ssh: -o ServerAliveInterval=15 -o ServerAliveCountMax=3



                                        You don't have to edit /etc/ssh/*config files if you do this.



                                        You can create an bash alias or function or script to make this easy.



                                        E.g. these bash functions, you can add into your .bashrc, do_ssh is used manually to turn on keepalives. do_ssh_pty is used within scripts to set pty and avoid prompts.



                                        do_ssh() {
                                        ssh -o ServerAliveInterval=15 -o ServerAliveCountMax=3 $*
                                        }

                                        do_ssh_pty() {
                                        ssh -tt -o "BatchMode=yes" -o "StrictHostKeyChecking=no" -o ServerAliveInterval=15 -o ServerAliveCountMax=3 $*
                                        }


                                        Now do_ssh user@host can be used or do_ssh user@host <args> <command> and keepalives will be active.






                                        share|improve this answer













                                        You can add these args every time you invoke ssh: -o ServerAliveInterval=15 -o ServerAliveCountMax=3



                                        You don't have to edit /etc/ssh/*config files if you do this.



                                        You can create an bash alias or function or script to make this easy.



                                        E.g. these bash functions, you can add into your .bashrc, do_ssh is used manually to turn on keepalives. do_ssh_pty is used within scripts to set pty and avoid prompts.



                                        do_ssh() {
                                        ssh -o ServerAliveInterval=15 -o ServerAliveCountMax=3 $*
                                        }

                                        do_ssh_pty() {
                                        ssh -tt -o "BatchMode=yes" -o "StrictHostKeyChecking=no" -o ServerAliveInterval=15 -o ServerAliveCountMax=3 $*
                                        }


                                        Now do_ssh user@host can be used or do_ssh user@host <args> <command> and keepalives will be active.







                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered Feb 12 '18 at 13:05









                                        gaoithegaoithe

                                        38727




                                        38727























                                            0














                                            I posted my answer here, as it was not a Ubuntu VM.



                                            https://unix.stackexchange.com/questions/259225/packet-write-wait-broken-pipe-even-leaving-top-running



                                            ssh -o IPQoS=throughput user@host





                                            share|improve this answer




























                                              0














                                              I posted my answer here, as it was not a Ubuntu VM.



                                              https://unix.stackexchange.com/questions/259225/packet-write-wait-broken-pipe-even-leaving-top-running



                                              ssh -o IPQoS=throughput user@host





                                              share|improve this answer


























                                                0












                                                0








                                                0







                                                I posted my answer here, as it was not a Ubuntu VM.



                                                https://unix.stackexchange.com/questions/259225/packet-write-wait-broken-pipe-even-leaving-top-running



                                                ssh -o IPQoS=throughput user@host





                                                share|improve this answer













                                                I posted my answer here, as it was not a Ubuntu VM.



                                                https://unix.stackexchange.com/questions/259225/packet-write-wait-broken-pipe-even-leaving-top-running



                                                ssh -o IPQoS=throughput user@host






                                                share|improve this answer












                                                share|improve this answer



                                                share|improve this answer










                                                answered 14 mins ago









                                                rupert160rupert160

                                                1112




                                                1112















                                                    Popular posts from this blog

                                                    GameSpot

                                                    日野市

                                                    Tu-95轟炸機